Last active
December 21, 2015 10:39
-
-
Save liquiddandruff/6293050 to your computer and use it in GitHub Desktop.
Little script that renames all files in the script's current directory to a base string and file type.
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 msvcrt | |
import os | |
import sys | |
import string | |
currentDirectory = os.path.split(sys.argv[0])[0] | |
fileNames = [ f for f in os.listdir(currentDirectory) if os.path.isfile(os.path.join(currentDirectory,f)) ] | |
# Don't include the script | |
numFiles = len(fileNames) - 1 | |
# Don't change the names of these files | |
skip = ["Thumbs.db"] | |
baseName = raw_input("Base File Name: ") | |
baseType = raw_input("Base File Type: ") | |
# Skip a line (for looks) | |
''' | |
Get new names from baseName and baseTypes | |
''' | |
fileNum = 0 | |
newFileNames = {} | |
for fileName in fileNames: | |
# If current file ends in py or is exempt, rename itself (ie. unchanged) | |
if fileName[-2:] == 'py' or fileName in skip: | |
print "Skipped: " + fileName | |
newFileNames[fileName] = fileName | |
continue | |
fileNum += 1 | |
terminate = None | |
# Check if baseType includes period, include if it doesn't | |
if "." in baseType: | |
terminate = baseType | |
else: | |
terminate = "." + baseType | |
# Append together current file's name | |
newFileName = baseName + " " + str(fileNum) + terminate | |
# Done | |
newFileNames[fileName] = newFileName | |
print "OLD: " + fileName | |
print "NEW: " + newFileName | |
# Finish | |
print "\nProceed? y/n: " | |
ver = msvcrt.getch().lower() | |
if ver == 'y': | |
for fileName in fileNames: | |
rename(fileName, newFileNames[fileName]) | |
elif ver == 'n': | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment