python 实现目录的递归复制
2015-09-02 18:13
671 查看
线上有需求,就是根据一个文件列表,去复制到相应的目录,而且要保持目录结构。
贴代码
本文出自 “wolf_ribble@163.com” 博客,请务必保留此出处http://ribble.blog.51cto.com/3863110/1690895
贴代码
#!/usr/bin/env python ##coding=utf-8 print """ 从存储服务器导出到临时目录 """ import os import shutil from os.path import exists, abspath, dirname, isfile des_dir = "/data" f = open('file.list', 'r') file = f.readlines() for i in file: if isfile(i.rstrip()): src_file_path = abspath(i.rstrip()) src_dir_path = dirname(src_file_path) des_dir_full = des_dir + src_dir_path des_file_full = des_dir + src_file_path if not exists(des_dir_full): os.makedirs(des_dir_full) if not exists(des_file_full) and exists(src_file_path): shutil.copy(src_file_path, des_dir_full)
本文出自 “wolf_ribble@163.com” 博客,请务必保留此出处http://ribble.blog.51cto.com/3863110/1690895
相关文章推荐
- (三)处理数据列表
- (一)下载python(推荐32位的版本,为了以后下载库方便)
- 2015/9/2 Python基础(7):元组
- 检测python进程是否存活
- 利用Python内置函数计算当前时间
- [Python开发] python使用Image合并图像
- 以此作为自己 python blog 里程的开始
- #!/usr/bin/env python与#!/usr/bin/python的区别
- 在Python的Flask框架中验证注册用户的Email的方法
- [转] Python 模块学习:os模块
- python学习笔记:子类怎样调用父类方法
- Python语法精要
- python脚本批量修改华为交换机端口配置
- 轻松python之文件专题-关于zip文件的一些操作
- 轻松python之文件专题-关于zip文件的一些操作
- python教程网址
- Hadoop2.6.0使用Python操作HDFS的解决方案
- Head First Python 学习笔记-Chapter6:自定义数据对象:字典与类
- Google Python Class 学习笔记(1) Introduce String list del
- OpenCV_Python学习笔记--OpenCV中的绘图函数