Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created April 1, 2020 17:20
Show Gist options
  • Save wbhinton/8aed9879282dc44b888b053beb778fe1 to your computer and use it in GitHub Desktop.
Save wbhinton/8aed9879282dc44b888b053beb778fe1 to your computer and use it in GitHub Desktop.
Move all files from subfolders in a parent directory up to the parent directory. It essentially flattens a folder structure, dumping all files into the parent folder.
import os
import shutil
target = input("What is the starting directory?")
def files2parent(target):
for root, dirs, files in os.walk(target):
for file in files:
try:
path_file = os.path.join(root,file)
shutil.move(path_file,target)
except: pass
files2parent(target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment