Skip to content

Instantly share code, notes, and snippets.

@bgoonz
Created June 17, 2022 04:36
Show Gist options
  • Select an option

  • Save bgoonz/bc64062b16c60f661f61cb8d936412e9 to your computer and use it in GitHub Desktop.

Select an option

Save bgoonz/bc64062b16c60f661f61cb8d936412e9 to your computer and use it in GitHub Desktop.
rename-files-after-parent-folder.py
# Moving all files in a directory to a subdirectory with the same name as the file.
#!/usr/bin/env python3
import shutil
import os
import sys
dr = sys.argv[1]
for root, dirs, files in os.walk('./'):
for f in files:
shutil.move(root+"/"+f, root+"/"+root.split("/")[-1]+f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment