Moving all files from one directory to another using Python

前端 未结 9 1651
长发绾君心
长发绾君心 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:17

    Try this:

    import shutil
    import os
        
    source_dir = '/path/to/source_folder'
    target_dir = '/path/to/dest_folder'
        
    file_names = os.listdir(source_dir)
        
    for file_name in file_names:
        shutil.move(os.path.join(source_dir, file_name), target_dir)
    

提交回复
热议问题