Created
July 8, 2018 21:22
-
-
Save telmotrooper/6fa9e0716e72b140048bde2076718a68 to your computer and use it in GitHub Desktop.
Batch file/folder renamer without regular expressions
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
from os import listdir, rename | |
from os.path import join, isdir | |
from readline import parse_and_bind | |
def main(): | |
print("Batch Rename - Developed by Telmo H. V. Silva") | |
print("-" * 50) | |
parse_and_bind("control-v: paste") | |
dir = input("Paste the directory here: ") | |
if(not isdir(dir)): | |
print("Invalid directory.") | |
return | |
oldList = listdir(dir) | |
newList = list() | |
oldText = input("Paste the text to be replaced: ") | |
newText = input("Paste the text to replace it: ") | |
i = 0 | |
while(i < len(oldList)): | |
newList.append(oldList[i].replace(oldText, newText)) | |
i += 1 | |
i = 0 | |
while(i < len(oldList)): | |
oldFile = join(dir, oldList[i]) | |
newFile = join(dir, newList[i]) | |
rename(oldFile, newFile) | |
i += 1 | |
print("Done!") | |
return | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment