批量建立資料夾

2021-09-26 19:40:58 字數 535 閱讀 8810

import os			#匯入模組

path =

'./test/'

#設定建立後資料夾存放的位置

for i in

range(30

,41):

#這裡建立10個資料夾

# *定義乙個變數判斷檔案是否存在,path指代路徑,str(i)指代資料夾的名字*

k ="%03d"

% i i***ists = os.path.exists(path+

str(k))if

not i***ists:

#判斷如果檔案不存在,則建立

os.makedirs(path+

"cycle_"

+str

(k))

print

("%s 目錄建立成功"

%k)else

:print

("%s 目錄已經存在"

%k)continue

#如果檔案不存在,則繼續上述操作,直到迴圈結束

python批量建立資料夾

有時需要建立一些同型別的資料夾儲存階段性的檔案,可以py指令碼實現批量建立資料夾 首先建立資料夾有兩個api 建立單層資料夾 import os path dir example ifnot os.path.exists path os.mkdir path 遞迴建立資料夾 import os pa...

python批量建立資料夾

參考資料 python os.path.join 產生的斜槓在windows和linux下的不同表現和解決方法 python獲取指定目錄下所有檔名os.walk和os.listdir 使用os.listdir 獲取路徑下所有檔名 判斷是否是資料夾有多種判斷方式,我使用if in top files ...

windows批量建立資料夾

後處理的時候需要建立非常多的資料夾用以存放資料,而且資料夾的名字是有規律的。手動建立的話非常慢而且繁瑣,於是就搜尋批量建立資料夾的方法。在windows中可以用bat命令實現批量建立資料夾,但首先需要得到資料夾的名字。這可以用excel來實現。比如,我要建立的資料夾的名字只包含數字,從641到670...