国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

用python實現(xiàn)的可以拷貝或剪切一個文件列表中的所有文件

2020-02-23 04:44:34
字體:
來源:轉載
供稿:網(wǎng)友
代碼如下:
# 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
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 正安县| 蛟河市| 中宁县| 高邮市| 偏关县| 定结县| 峨眉山市| 宕昌县| 深州市| 永安市| 大田县| 济南市| 孟州市| 尼玛县| 治县。| 德化县| 姜堰市| 山阳县| 孝感市| 昌都县| 卫辉市| 新竹市| 广西| 罗源县| 阿图什市| 荆州市| 和田市| 大埔县| 类乌齐县| 锡林浩特市| 全州县| 盐山县| 报价| 巴楚县| 黄梅县| 寿光市| 乐亭县| 江都市| 卢氏县| 蕉岭县| 凤台县|