Skip to content

Instantly share code, notes, and snippets.

@dipinpjoseph
Last active May 7, 2018 08:19
Show Gist options
  • Save dipinpjoseph/2ac63d6ce3fcddcb0f90af1a3a450ba1 to your computer and use it in GitHub Desktop.
Save dipinpjoseph/2ac63d6ce3fcddcb0f90af1a3a450ba1 to your computer and use it in GitHub Desktop.
Piece of code in Python that helps in bulk renaming of files.
import os
import random
import sys
baseName = ' '.join(sys.argv[1:])
print (baseName)
with open('postFixList.txt') as f:
lines = f.read().splitlines()
print(lines)
cwd = os.getcwd()
folder = "FileList"
folderPath = os.path.join(cwd,folder)
print(folderPath)
for eachFile in os.listdir(folderPath):
filename = os.path.splitext(eachFile)[0]
print (filename)
extension = os.path.splitext(eachFile)[1]
print (extension)
updateName = baseName + " " +random.choice(lines) + extension
print(updateName)
os.rename(os.path.join(folderPath, eachFile), os.path.join(folderPath, updateName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment