-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_folder_file.py
More file actions
32 lines (28 loc) · 949 Bytes
/
os_folder_file.py
File metadata and controls
32 lines (28 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
path="C:/Users/jayw7/OneDrive/桌面"
os.makedirs(path+"/music/a/b", exist_ok =True)
# 函數功能: 顯示指定路徑下,該層的檔案及資料夾名稱
def batch_showname(path):
listdir1=os.listdir(path)
print(listdir1)
print(type(listdir1))
for fname in listdir1:
print(os.path.join(path, fname))
batch_showname("C:")
# 函數功能: 遞迴顯示指定路徑下的所有檔案及資料夾名稱
def find_dir(path):
for fd in os.listdir(path):
full_path=os.path.join(path,fd)
if os.path.isdir(full_path):
print('資料夾:',full_path)
find_dir(full_path)
else:
print('檔案:',full_path)
#find_dir("C:/Users/jayw7/OneDrive/桌面")
def path_convert(path):
c1='\\'
c2='//'
return [l for l in path if l != c1 else c2].join('')
ans="C:\Users\jayw7\OneDrive\桌面"
print(ans)
print(path_convert(ans))