文件移动
import os # from main import run #import shutil path_to_watch = r'C:UsersAdministratorDesktop estpath_to_watch' # file_path = r"C:UsersAdministratorDesktop est mp" #right_path = r"C:UsersAdministratorDesktop est ight_path" #wrong_path = r"C:UsersAdministratorDesktop estwrong_path" move_path = r"C:UsersAdministratorDesktop estmove_path" while 1: if os.listdir(path_to_watch): print("ppp", os.listdir(path_to_watch)) for file in os.listdir(path_to_watch): # # run(path_to_watch, right_path, wrong_path) # print("file", file) i = 1 file1 = file while os.path.exists(os.path.join(move_path,file1)) file1 = ('_d'+str(i).rjust(3,'0')).join(os.path.splitext(file)) i += 1 #或者如果存在先删掉 os.rename(os.path.join(path_to_watch,file), os.path.join(move_path,file1)) #os.remove(os.path.join(path_to_watch, file))
参考资料: