AyanUpadhaya

Move files python script

May 2nd, 2021 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. import os
  2. import shutil
  3.  
  4. source='c:/users/ayanU/Desktop'
  5. destination='c:/users/ayanU/Desktop/text'
  6.  
  7. #change the directory
  8. os.chdir(source)
  9.  
  10. #look for text files
  11.  
  12. files=os.listdir(source)
  13. ext=".txt"
  14. #make a loop to check all files and if .txt move to destination
  15.  
  16. for file in files:
  17. if ext in file:
  18. shutil.move(file,destination)
Add Comment
Please, Sign In to add comment