Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created November 30, 2018 22:41
Show Gist options
  • Select an option

  • Save mhweber/fdcb482c65c33d2e44dda2caad413c90 to your computer and use it in GitHub Desktop.

Select an option

Save mhweber/fdcb482c65c33d2e44dda2caad413c90 to your computer and use it in GitHub Desktop.
Rename multiple files in a directory using list comprehension
import os
path = 'some/path'
[os.rename(f, f.replace('some_text','new_text')) for f in os.listdir(path) if f.count('text_to_look_for')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment