Moving all files from one directory to another using Python

前端 未结 9 1765
长发绾君心
长发绾君心 2020-12-24 00:57

I want to move all text files from one folder to another folder using Python. I found this code:

import os, shutil, glob

dst = \'/path/to/dir/Caches/com.app         


        
9条回答
  •  醉酒成梦
    2020-12-24 01:23

    For example, if I wanted to move all .txt files from one location to another ( on a Windows OS for instance ) I would do it something like this:

    import shutil
    import os,glob
    
    inpath = 'R:/demo/in' 
    outpath = 'R:/demo/out'
    
    os.chdir(inpath)
    for file in glob.glob("*.txt"):
    
        shutil.move(inpath+'/'+file,outpath)
    

提交回复
热议问题