Skip to content

Instantly share code, notes, and snippets.

@eupendra
Created June 24, 2021 08:26
Show Gist options
  • Save eupendra/0bd01166f983c18b3efb35ce16e8bf4c to your computer and use it in GitHub Desktop.
Save eupendra/0bd01166f983c18b3efb35ce16e8bf4c to your computer and use it in GitHub Desktop.
I wrote this to rename my mp3 files to remove unwanted text like junk, backup etc. Used `renames` instead of `rename` so that new directories can be created as well.
strip_text=['junk','backup']
for fn in glob.glob("**/*.mp3", recursive=True):
f=os.path.abspath(fn)
try:
for t in strip_text:
if t in f:
new_f=f.replace(t,"").strip()
os.renames(f, new_f)
f=new_f
except:
pass #ignore file in use etc
print('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment