Skip to content

Instantly share code, notes, and snippets.

@mprostock
Last active August 6, 2019 15:21
Show Gist options
  • Save mprostock/a8f8246ac65e3210b01af0588ed83fd8 to your computer and use it in GitHub Desktop.
Save mprostock/a8f8246ac65e3210b01af0588ed83fd8 to your computer and use it in GitHub Desktop.
quick script to rename all files in a folder
"""
very quick and dirty batch renamer - needed for downloaded files
"""
import sys
from pathlib import Path
if len(sys.argv)<2:
print("usage: renamer.py FOLDER")
print("argument 'FOLDER' missing.")
sys.exit(1)
folder = sys.argv[1]
folder = Path(folder)
try:
for p in folder.iterdir():
newname = p.name.replace("'","")
# newname = newname.replace(","," -")
# print(p.name, " - ", newname)
p.rename(folder/newname)
except Exception as e:
print(repr(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment