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

首頁(yè) > 編程 > Python > 正文

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

2019-11-25 18:44:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

# 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) 


傳一個(gè)文件給該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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 盐津县| 西安市| 哈密市| 当阳市| 屯门区| 上思县| 云阳县| 沈丘县| 怀仁县| 寿光市| 梁河县| 江津市| 康平县| 大足县| 湖北省| 乌什县| 留坝县| 广灵县| 扶沟县| 大宁县| 库尔勒市| 林甸县| 云龙县| 安仁县| 龙州县| 安福县| 额济纳旗| 阿坝| 乐昌市| 曲周县| 安庆市| 韩城市| 农安县| 虎林市| 长子县| 察隅县| 湖口县| 黔西| 郓城县| 漳平市| 浏阳市|