python 將一個資料夾內的不同型別檔案分別儲存到兩個不同的資料夾(json,png)

逐吧發表於2020-12-03

import os
import shutil

path1=r"C:\Users\ASUS\Desktop\3-45\3-4\1.2.826.0.1.3680043.2.951.23237813\1.2.826.0.1.3680043.2.951.23237813"
path2=r"C:\Users\ASUS\Favorites\json"
path3=r"C:\Users\ASUS\Favorites\png"

for file in os.listdir(path1):
if file.endswith(.json):
path=os.path.join(path1,file)
shutil.move(path,path2)
elif file.endswith(.png):
path=os.path.join(path1,file)
shutil.move(path,path2)

相關文章