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

时间:2022-09-11 11:28:23 


# 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,剪切,拷贝
0
投稿

猜你喜欢

  • asp生成不需要数据库的中奖码

    2008-07-18 12:31:00
  • kali添加开机自启的方法

    2023-06-06 04:15:06
  • Django CBV与FBV原理及实例详解

    2023-02-14 20:39:01
  • Centos7 安装 PHP7最新版的详细教程

    2023-10-16 21:14:12
  • python 操作mysql数据中fetchone()和fetchall()方式

    2024-01-19 11:02:18
  • js版实现计算器功能

    2024-04-23 09:26:42
  • python jieba库的基本使用

    2022-10-15 23:01:16
  • Python利用turtle库绘制彩虹代码示例

    2022-03-04 03:55:01
  • Python机器学习应用之基于天气数据集的XGBoost分类篇解读

    2023-09-12 05:45:07
  • python3获取两个日期之间所有日期,以及比较大小的实例

    2023-01-31 06:54:52
  • 在Linux系统上同时监控多个Oracle数据库表空间的方法

    2024-01-20 20:29:29
  • MySQL数据库基于sysbench实现OLTP基准测试

    2024-01-28 11:07:14
  • 用MySQL创建数据库和数据库表代码

    2024-01-24 01:12:06
  • pandas中的数据去重处理的实现方法

    2022-05-13 23:28:50
  • 轻松学习jQuery插件EasyUI EasyUI创建RSS Feed阅读器

    2024-05-03 15:31:44
  • 对python当中不在本路径的py文件的引用详解

    2022-12-17 15:12:42
  • 如何用python将单引号替换为双引号

    2023-06-19 06:26:29
  • python turtle库画圣诞树详细代码教程

    2022-09-20 10:29:33
  • MySQL数据库21条最佳性能优化经验

    2024-01-14 13:17:11
  • MySQL使用变量实现各种排序

    2024-01-22 10:36:14
  • asp之家 网络编程 m.aspxhome.com