用python实现的可以拷贝或剪切一个文件列表中的所有文件


Posted in Python onApril 30, 2009
# coding:utf-8 
import os 
import sys 
def cut_and_paste_file(source, destination): 
    ''' 
    source: file path 中文 
    destination: directory path 
    ''' 
    def format_path(path): 
        if not os.path.isabs(path): 
            path = os.path.join(os.getcwd(), path) 
        return path 
    def mk_dir(path): 
        if not os.path.exists(os.path.dirname(path)): 
            mkdir_cmd = 'mkdir "%s"' % os.path.dirname(path) 
            print os.popen(mkdir_cmd).read()     destination = os.path.join(format_path(destination), source) 
    source = format_path(source) 
    mk_dir(source) 
    mk_dir(destination) 
    copy_cmd = 'copy /Y "%s" "%s"' % (source, destination) 
    print 'copy_cmd:%s' % copy_cmd 
    print os.popen(copy_cmd).read() 
    del_cmd = 'del "%s" /Q' % source 
    print 'del_cmd:%s' % del_cmd 
    print os.popen(del_cmd).read() 
if __name__ == '__main__': 
    if len(sys.argv) != 2: 
        print 'params must be 1,the params is the file of contain the list of cutAndPastFile List' 
        exit(0) 
    file_name = sys.argv[1] 
    f = open(file_name, 'r') 
    lst_file = f.readlines() 
    f.close() 
    output_path = 'backup_del' 
    for filename in lst_file: 
        filename = filename.replace('\n', '') 
        if filename != '': 
            cut_and_paste_file(filename, output_path) 

传一个文件给该py文件即可,例如,文件名为:del_file.txt
group1_input\subgroup13\55657_XSL_Transformations_(XSLT)_Version_2.0.doc
group1_input\subgroup6\377-6700-001 REV B .doc
group3_input\subgroup42\CGP_Manual_5_0.doc
Python 相关文章推荐
python模拟鼠标拖动操作的方法
Mar 11 Python
python列表操作之extend和append的区别实例分析
Jul 28 Python
Windows下安装python MySQLdb遇到的问题及解决方法
Mar 16 Python
Python整型运算之布尔型、标准整型、长整型操作示例
Jul 21 Python
Python tkinter实现的图片移动碰撞动画效果【附源码下载】
Jan 04 Python
Sanic框架路由用法实例分析
Jul 16 Python
详解python配置虚拟环境
Apr 08 Python
python实现密码强度校验
Mar 18 Python
Django Channel实时推送与聊天的示例代码
Apr 30 Python
利用OpenCV中对图像数据进行64F和8U转换的方式
Jun 03 Python
浅谈OpenCV中的新函数connectedComponentsWithStats用法
Jul 05 Python
python使用scapy模块实现ARP扫描的过程
Jan 21 Python
Python 自动安装 Rising 杀毒软件
Apr 24 #Python
Python 解析XML文件
Apr 15 #Python
合并Excel工作薄中成绩表的VBA代码,非常适合教育一线的朋友
Apr 09 #Python
python thread 并发且顺序运行示例
Apr 09 #Python
python 判断一个进程是否存在
Apr 09 #Python
python ElementTree 基本读操作示例
Apr 09 #Python
python 获取et和excel的版本号
Apr 09 #Python
You might like
php REMOTE_ADDR之获取访客IP的代码
2008/04/22 PHP
php 读取文件乱码问题
2010/02/20 PHP
微博短链接算法php版本实现代码
2012/09/15 PHP
php中Ioc(控制反转)和Di(依赖注入)
2017/05/07 PHP
thinkPHP5框架自定义验证器实现方法分析
2018/06/11 PHP
PHP封装cURL工具类与应用示例
2019/07/01 PHP
PHP 实现base64编码文件上传出现问题详解
2020/09/01 PHP
写的htc的数据表格
2007/01/20 Javascript
JavaScipt基本教程之JavaScript语言的基础
2008/01/16 Javascript
jQuery中removeAttr()方法用法实例
2015/01/05 Javascript
本人自用的global.js库源码分享
2015/02/28 Javascript
Backbone.js 0.9.2 源码注释中文翻译版
2015/06/25 Javascript
javascript中tostring()和valueof()的用法及两者的区别
2015/11/16 Javascript
详解js产生对象的3种基本方式(工厂模式,构造函数模式,原型模式)
2017/01/09 Javascript
Python实现的金山快盘的签到程序
2013/01/17 Python
Python列表推导式的使用方法
2013/11/21 Python
Python实现将doc转化pdf格式文档的方法
2018/01/19 Python
Python爬虫获取图片并下载保存至本地的实例
2018/06/01 Python
python中int与str互转方法
2018/07/02 Python
Selenium(Python web测试工具)基本用法详解
2018/08/10 Python
详解Python是如何实现issubclass的
2019/07/24 Python
Backcountry旗下的户外商品闪购网站:steep&cheap
2016/09/22 全球购物
师范教师毕业鉴定
2014/01/13 职场文书
学习经验交流会主持词
2014/04/01 职场文书
报告会主持词
2014/04/02 职场文书
农林经济管理专业自荐信
2014/09/01 职场文书
个人职业及收入证明
2014/10/13 职场文书
学生评语集锦
2015/01/04 职场文书
婚礼答谢礼品
2015/01/20 职场文书
小学三八妇女节活动总结
2015/02/06 职场文书
2015年七七事变78周年纪念活动方案
2015/05/06 职场文书
python 模拟在天空中放风筝的示例代码
2021/04/21 Python
go语言中http超时引发的事故解决
2021/06/02 Golang
Spring this调用当前类方法无法拦截的示例代码
2022/03/20 Java/Android
MySQL分区路径子分区再分区
2022/04/13 MySQL
Python 数据可视化工具 Pyecharts 安装及应用
2022/04/20 Python