Skip to content

Instantly share code, notes, and snippets.

@santiago-salas-v
Created January 4, 2018 22:24
Show Gist options
  • Save santiago-salas-v/aee6fd3637a2f555e6d067d349652974 to your computer and use it in GitHub Desktop.
Save santiago-salas-v/aee6fd3637a2f555e6d067d349652974 to your computer and use it in GitHub Desktop.
recursively walk and replace file names containing str '[replaceme]'
import os
replace_str = '[replaceme]'
for root, dirs, files in os.walk('.'):
for file in files:
if replace_str in file:
new_file = file.replace(replace_str,'')
os.rename(
os.path.join(root,file),
os.path.join(root,new_file)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment