移动文件
有移动文件的烦恼?递归移动指定文件后缀的文件
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 协议》,转载必须注明作者和本文链接