有移動檔案的煩惱?遞迴移動指定檔案字尾的檔案
import os
import shutil
def move_file(orgin_path, moved_path):
dir_files = os.listdir(orgin_path)
for file in dir_files:
file_path = os.path.join(orgin_path, file)
if os.path.isfile(file_path):
if file.endswith(".mp4"):
if os.path.exists(os.path.join(moved_path, file)):
print("有重複檔案!!!")
continue
else:
shutil.move(file_path, moved_path)
if os.path.isdir(file_path):
move_file(file_path, moved_path)
print("移動檔案成功!")
if __name__ == '__main__':
orgin_path = 'F:\\Video\\temp\\'
moved_path = 'F:\\temp\\'
move_file(rootPath, destDir)
本作品採用《CC 協議》,轉載必須註明作者和本文連結