python实现将一个文件夹下的文件分类,并剪切到其他文件夹
import os
import shutil
dir_path=r'E:/hlc_workspace/dir1'
file_list=os.listdir(dir_path)
dir2_dst=r'E:/hlc_workspace/dir2'
dir3_dst=r'E:/hlc_workspace/dir3'
dir4_dst=r'E:/hlc_workspace/dir4'
dir5_dst=r'E:/hlc_workspace/dir5'
print('正在迁移文件中.........')
for f in file_list:
if 'STR2' in f:
shutil.move(os.path.join(dir_path,f),dir2_dst)
elif 'STR3' in f:
shutil.move(os.path.join(dir_path, f), dir3_dst)
elif 'STR4' in f:
shutil.move(os.path.join(dir_path, f), dir4_dst)
else:
shutil.move(os.path.join(dir_path, f), dir5_dst)
print('文件分类并迁移完毕!')