python copy files by wildcards

后端 未结 3 825
梦毁少年i
梦毁少年i 2020-11-30 04:41

I am learning python (python 3) and I can copy 1 file to a new directory by doing this

import shutil 
shutil.copyfile(\'C:/test/test.txt\', \'C:/lol/test.txt         


        
3条回答
  •  -上瘾入骨i
    2020-11-30 05:11

    import glob
    import shutil
    dest_dir = "C:/test"
    for file in glob.glob(r'C:/*.txt'):
        print(file)
        shutil.copy(file, dest_dir)
    

提交回复
热议问题