当前位置 博文首页 > LY的博客:shutil.copy 使用python复制指定文件

    LY的博客:shutil.copy 使用python复制指定文件

    作者:[db:作者] 时间:2021-08-02 12:42

    #coding=utf-8
    import shutil
    import os
    
    #windows 环境下
    src = 'D:\\2019年-银行证券保险'
    des ='D:\\out'
    
    codelist=['600030',
    '601066',
    '601688',
    '600837',
    '601211',
    '600999',
    '601881',
    '601236',
    '600958',
    '601901',
    '601696',
    '601788',
    '600061',
    '601990',
    '601377',
    '601162',
    '601108',
    '601878',
    '601555',
    '601198',
    '600109',
    '600909',
    '600369',
    '601099',
    '600155',
    '601375',
    '600621',
    '600864'
    ]
    
    namelist=[]
    for x in os.listdir(src):
        if '.xlsx' in x:
            for code in codelist:
                if code in x:
                    #print(code)
    
                    namelist.append(x)
                    break
    
    
    print(namelist)
    
    
    
    for filename in namelist:
    
    
        shutil.copyfile(os.path.join(src, filename), os.path.join(des, filename))#目标文件无需存在
    
    

    ?

    cs
    下一篇:没有了