Skip to content

Instantly share code, notes, and snippets.

@arjitg
Created May 24, 2019 18:14
Show Gist options
  • Save arjitg/d00dee226fc32a89390d068a2b74dc0e to your computer and use it in GitHub Desktop.
Save arjitg/d00dee226fc32a89390d068a2b74dc0e to your computer and use it in GitHub Desktop.
A script I whipped to automate moving files inside various folders collectively into another master folder. Around 70 GB of data was moved in a couple of minutes.
import os
import send2trash
source_root = "E:\\storage\\nexus6p"
destination = "E:\\storage\\nexus6p\\allpics"
#to move files from various subfolders to another folder. Takes care of repeated files too
for root, dirs, files in os.walk(source_root):
print("in {}, moving {} to {}".format(root, files, destination))
for file in files:
try:
os.rename(os.path.join(root, file), os.path.join(destination, file))
except FileExistsError:
pass
#The below is to remove empty folders and send them to the recycle bin.
allfolders = os.listdir("E:\\storage\\nexus6p")
for folder in allfolders:
if os.path.getsize(folder) == 0:
send2trash.send2trash(folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment