码迷,mamicode.com
首页 > 编程语言 > 详细

Python 文件操作

时间:2020-02-26 19:18:14      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:blank   rom   while   imp   python   desktop   des   ext   ref   

文件移动

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))

  参考资料:

os文件/目录操作方法

Python 文件操作

标签:blank   rom   while   imp   python   desktop   des   ext   ref   

原文地址:https://www.cnblogs.com/iupoint/p/12368070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!