Skip to content

Instantly share code, notes, and snippets.

@bryanbuchanan
Created March 10, 2018 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanbuchanan/437c769e018f221136875fbd533d06d2 to your computer and use it in GitHub Desktop.
Save bryanbuchanan/437c769e018f221136875fbd533d06d2 to your computer and use it in GitHub Desktop.
import os
import sys
directory = os.path.dirname(os.path.realpath(sys.argv[0]))
for subdir, dirs, files in os.walk(directory):
for filename in files:
if filename.find('old_suffix_1') > 0:
subdirectoryPath = os.path.relpath(subdir, directory)
filePath = os.path.join(subdirectoryPath, filename)
newFilePath = filePath.replace("old_suffix_1", ".")
os.rename(filePath, newFilePath)
elif filename.find('old_suffix_2') > 0:
subdirectoryPath = os.path.relpath(subdir, directory)
filePath = os.path.join(subdirectoryPath, filename)
newFilePath = filePath.replace("old_suffix_2", "_image_")
os.rename(filePath, newFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment