python拷贝文件
来源:互联网 发布:网络基础架构的理解 编辑:程序博客网 时间:2024/05/14 22:36
import os, os.path, shutil, time, datetime#copy file from one dir to anotherdef copyFiles(sourceDir, targetDir): for file in os.listdir(sourceDir): sourceFile = os.path.join(sourceDir, file) targetFile = os.path.join(targetDir, file) if os.path.isfile(sourceFile): if not os.path.exists(targetDir): os.makedirs(targetDir) if not os.path.exists(targetFile) or (os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))): open(targetFile, "wb").write(open(sourceFile, "rb").read()) if os.path.isdir(sourceFile): copyFiles(sourceFile, targetFile)#remove file from dirdef removeFileInFirstDir(targetDir): for file in os.listdir(targetDir): targetFile = os.path.join(targetDir, file) if os.path.isfile(targetFile): os.remove(targetFile)#def coverFiles(sourceDir, targetDir): for file in os.listdir(sourceDir): sourceFile = os.path.join(sourceDir, file) targetFile = os.path.join(targetDir, file) if os.path.isfile(sourceFile): open(targetFile, "wb").write(open(sourceFile, "rb").read())#def moveFileto(sourceDir, targetDir): if not os.path.exists(targetDir): os.makedirs(targetDir) shutil.copy(sourceDir, targetDir)#write data into filedef writeVersionInfo(targetFile): open(targetFile, "wb").write("Revison:")#get current timedef getCurTime(): nowTime = time.localtime() year = str(nowTime.tm_year) month = str(nowTime.tm_mon) if len(month) < 2: month = '0' + month day = str(nowTime.tm_yday) if len(day) < 2: day = '0' + day return year + '-' + month + '-' + day#MainTarget_File_Path = "/Users/jianan/Desktop/"Debug_File_Path = "/Users/jianan/Desktop/Test"if __name__ == "__main__": print "Start(S) or Quit(Q);n" flag = True while flag: answer = raw_input() if 'Q' == answer: flag = False elif 'S' == answer: formatTime = getCurTime() targetFoldername = "Build" + formatTime Target_File_Path += targetFoldername coverFiles(Debug_File_Path, Target_File_Path) # copyFiles(Debug_File_Path, Target_File_Path) # removeFileInFirstDir(Target_File_Path) # moveFileto(Debug_File_Path+"/python.txt", Target_File_Path) # writeVersionInfo(Target_File_Path + "\\ReadMe.txt") print "Done..." else: print "not the correct command"
0 0
- python文件拷贝代码
- Python文件拷贝-shutil
- Python 拷贝文件
- python文件拷贝
- python拷贝文件
- python拷贝文件
- 【Python】删除和拷贝文件
- python指定后缀文件拷贝
- Python文件操作--文件拷贝&文件合并
- 【python】通过paramiko远程拷贝文件
- python 实现文件的递归拷贝-转
- python文件拷贝工具shutil介绍
- Python行读取文件进行拷贝
- python 文件拷贝copy操作 shutill
- 第17个python程序:拷贝文件
- 用python代码实现文件的拷贝
- python拷贝文件到U盘
- Python实现文件拷贝和解开权限
- Simbolic Link 软链接 (Windows Junction)
- swift 字符串的截取和拼接
- vim配色和终端的配色和Linux下中文输入法
- YAML
- github上排名一百的OC项目
- python拷贝文件
- 数据结构实验之栈一:进制转换
- 三星 galaxy s7 启用开发者模式
- Html5 history API
- C++之STL查找
- CGlib与Java Proxy的动态代理
- POJ 3301 Texas Trip(三分)
- Dagger2入门
- poj 1958 Cow Marathon(树的直径,模板题)