python 文件夹拷贝
来源:互联网 发布:苹果mac卸载软件 编辑:程序博客网 时间:2024/06/06 22:40
记录用python 处理文件以及文件夹的拷贝。
#coding:utf-8import osimport sysimport getpassimport shutil
# shutil.copyfile("oldfile","newfile") oldfile和newfile都只能是文件# 创建多级目录:os.makedirs("/Users/ximi/version")# 创建单个目录:os.mkdir("project")# #复制文件# shutil.copyfile('listfile.py', 'd:/test.py')# shutil.rmtree("dir") 空目录、有内容的目录都可以删# 检验给出的路径是否真地存:os.path.exists()username = getpass.getuser()# 改变当前工作目录os.chdir('/Users/' + username + '/Documents/client/myProj/')
文件的拷贝用shutil.copyfile(srcFilePath,dstFilePath)
def handleVersionFile(): srcVersionFilePath = os.getcwd()+os.sep+"res/version/version.manifest" dstVersionFilePath = os.getcwd()+os.sep+"tools/myProj/version/version.manifest" versionDir = os.getcwd()+os.sep+"tools/myProj/version/" if not os.path.exists(versionDir): print versionDir, '\n配置文件目录不存在,创建目录...' # os.mkdir(versionDir) os.makedirs(versionDir) print '创建配置文件目录成功!\n' srcProjectFilePath = os.getcwd()+os.sep+"res/version/project.manifest" dstProjectFilePath = os.getcwd()+os.sep+"tools/myProj/version/project.manifest" print '拷贝配置文件开始...' if os.path.exists(srcVersionFilePath): shutil.copyfile(srcVersionFilePath,dstVersionFilePath) if os.path.exists(srcProjectFilePath): shutil.copyfile(srcProjectFilePath,dstProjectFilePath) print '拷贝配置文件结束!\n'
文件夹的拷贝用shutil.rmtree(dstResDir)
def handleAssetsFile(): sourceSrcDir = os.getcwd()+os.sep+"src/" dstSrcDir = os.getcwd()+os.sep+"tools/myProj/assets/src/" sourceResDir = os.getcwd()+os.sep+"res/" dstResDir = os.getcwd()+os.sep+"tools/myProj/assets/res/" #复制目录,olddir和newdir都只能是目录,且newdir必须不存在 if os.path.exists(dstSrcDir): print dstSrcDir, '存在先删除' shutil.rmtree(dstSrcDir) print '拷贝代码文件夹开始...' shutil.copytree(sourceSrcDir, dstSrcDir) print '拷贝代码文件夹结束!\n' if os.path.exists(dstResDir): print dstResDir, '存在先删除' shutil.rmtree(dstResDir) print '拷贝资源文件夹开始...' shutil.copytree(sourceResDir, dstResDir) print '拷贝资源文件夹结束!\n'
if __name__ == "__main__": handleVersionFile() handleAssetsFile()
阅读全文
0 0
- Python拷贝/删除文件夹
- python 文件夹拷贝
- python实现文件夹目录拷贝
- 拷贝文件夹
- 拷贝文件夹
- 拷贝文件夹
- 文件夹拷贝
- 拷贝文件夹
- 文件夹拷贝
- 拷贝文件夹 删除文件夹
- 文件夹、文件夹内容拷贝
- python拷贝文件夹中特定日期内的文件
- Python多进程拷贝文件夹中的所有文件
- VB拷贝文件,拷贝文件夹
- 服务器端文件夹拷贝
- 拷贝复制文件夹
- linux的 拷贝文件夹
- Ant拷贝文件夹
- PDF转CAD工具怎么选择
- <android>retrofit入门
- C#编程入门20_委托、事件、Lambda表达式
- Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式 标签: tomcat 2016-09-06 11:28 2910人阅读 评论(0) 收藏 举报 分类: tomca
- java基础之内部类
- python 文件夹拷贝
- loopback 地址
- 【Leetcode-Easy-70】Climbing Stairs
- 5.Bullet
- The JRE could not be found.Edit the server and change the JRE location.
- 浅谈WAF绕过技巧
- JVM学习笔记-JAVA技术体系
- 虚拟环境下Django 环境安装
- hdu 5137 ( How Many Maos Does the Guanxi Worth )