How to move a file?

后端 未结 9 1844
夕颜
夕颜 2020-11-22 01:07

I looked into the Python os interface, but was unable to locate a method to move a file. How would I do the equivalent of $ mv ... in Python?

&g         


        
9条回答
  •  无人及你
    2020-11-22 01:20

      import os,shutil
    
      current_path = "" ## source path
    
      new_path = "" ## destination path
    
      os.chdir(current_path)
    
      for files in os.listdir():
    
            os.rename(files, new_path+'{}'.format(f))
            shutil.move(files, new_path+'{}'.format(f)) ## to move files from 
    

    different disk ex. C: --> D:

提交回复
热议问题