Python 文件操作
文件移动
import os # from main import run #import shutil path_to_watch = r‘C:\Users\Administrator\Desktop\test\path_to_watch‘ # file_path = r"C:\Users\Administrator\Desktop\test\tmp" #right_path = r"C:\Users\Administrator\Desktop\test\right_path" #wrong_path = r"C:\Users\Administrator\Desktop\test\wrong_path" move_path = r"C:\Users\Administrator\Desktop\test\move_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) file1 = ‘1‘.join(os.path.splitext(file)) if os.path.exists(os.path.join(move_path,file)) else file #或者如果存在先删掉 os.rename(os.path.join(path_to_watch,file), os.path.join(move_path,file1)) #os.remove(os.path.join(path_to_watch, file))
参考资料:
相关推荐
Nostalgiachild 2020-11-13
LUOPING0 2020-09-11
anglehearts 2020-07-18
freerocker 2020-06-16
libowenhit 2020-06-14
CCoder 2020-06-13
hulao 2020-06-13
tianyafengxin 2020-06-07
sdwylry 2020-06-02
zhangtianshun 2020-05-27
小方哥哥 2020-05-10
JamesRayMurphy 2020-05-08
LychieFan 2020-05-05
missingmuch 2020-04-30
hnllei 2020-04-27
nginxs 2020-03-26