Python moving files and directories from one folder to another

前端 未结 4 1687
别跟我提以往
别跟我提以往 2021-01-06 11:22

I would like to move in python files and directories in one directory to another directory with overwrite ability.

I started with the following code:



        
4条回答
  •  余生分开走
    2021-01-06 12:10

    This because os.listdir(path) return array according documentation here. So you should modify you code as following for moving files and directories.

        #moving files from progs
        path = tempfolder + 'progs/'
        for item_path in os.listdir(path):
            shutil.move(os.path.join(path, item_path) , os.path.join(compteurfolder, item_path)
    

提交回复
热议问题