Python 文件夹复制
发布时间:2020-05-25 00:59:58 所属栏目:Python 来源:互联网
导读:Python 文件夹复制
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 #! /usr/bin/env python
# -*- coding: utf-8 -*-
#@author [emailprotected]
#@version 2010-09-25 14:57
import os
import time
sourceDir = r"\192.168.3.250mmtimages"
targetDir = r"D:mmtimages"
copyFileCounts = 0
def copyFiles(sourceDir,targetDir):
global copyFileCounts
print sourceDir
print u"%s 当前处理文件夹%s已处理%s 个文件" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())),sourceDir,copyFileCounts)
for f in os.listdir(sourceDir):
sourceF = os.path.join(sourceDir,f)
targetF = os.path.join(targetDir,f)
if os.path.isfile(sourceF):
#创建目录
if not os.path.exists(targetDir):
os.makedirs(targetDir)
copyFileCounts += 1
#文件不存在,或者存在但是大小不同,覆盖
if not os.path.exists(targetF) or (os.path.exists(targetF) and (os.path.getsize(targetF) != os.path.getsize(sourceF))):
#2进制文件
open(targetF,"wb").write(open(sourceF,"rb").read())
print u"%s %s 复制完毕" %(time.strftime('%Y-%m-%d %H:%M:%S',targetF)
else:
print u"%s %s 已存在,不重复复制" %(time.strftime('%Y-%m-%d %H:%M:%S',targetF)
if os.path.isdir(sourceF):
copyFiles(sourceF,targetF)
if __name__ == "__main__":
try:
import psyco
psyco.profile()
except ImportError:
pass
copyFiles(sourceDir,targetDir)
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Python3计算三角形的面积代码
- python – Flask:使用全局变量将数据文件加载到内存中
- python – 通过Curl向Flask发送JSON-Request [复制]
- 是否有Python方法可以访问类的所有非私有和非内置属性?
- Python cookbook(数据结构与算法)字典相关计算问题示例
- Python实现监控程序执行时间并将其写入日志的方法
- 将Python的Django框架与认证系统整合的方法
- python如何存储字符串,以便’is’运算符可以处理文字?
- Python中列表元素转为数字的方法分析
- 【Python】多进程报错:DUPLICATE_SAME_ACCESS PermissionE
