Howto move files under child directories to somewhere via Python
When I need to move all .zip
files to /sharedfolders
, how should I do?
/sharedfolders/Archives/A/A.zip
/sharedfolders/Archives/A/B/AB.zip
/sharedfolders/Archives/B/B.zip
/sharedfolders/Archives/A/C/C.zip
/sharedfolders/Archives/A/D.zip
... (hundreds of subdirectories)
----
$ pwd
/sharedfolders
Manually move file is not a good solution :P Do it with python.
import os
import glob
import shutil
path = """/sharedfolders/Archives"""
files = [f for f in glob.glob(path + "/**/*.zip", recursive=True)]
for file in files:
file_name = os.path.basename(file)
shutil.move(file, path+"/"+file_name)