Last active
May 7, 2018 08:19
-
-
Save dipinpjoseph/2ac63d6ce3fcddcb0f90af1a3a450ba1 to your computer and use it in GitHub Desktop.
Piece of code in Python that helps in bulk renaming of files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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