A Python & Bash Script that can be used to rename Files, Folders, and Subfolders and also replace in files (Currently Supports Windows only) This is incredibly useful if you want to rename a folder structure that contains a word in multiple sub-branches. This script recursively goes over each and every file directory and edits not only the filename but also foldernames and its subcontents!!
Suppose you have a nested Structure with the word Rest appearing multiple times both in filenames, foldernames and inside the individual files like this:
hren -o Rest -n Test
All instances of Rest in your folders, filenames and inside your files has been replaced with Test. This has occured everywhere at the same time! Isnt this awesome?
- -o (or) --oldname -> This is the name that you want to replace
- -n (or) --newname -> This is the name name that you want to replace the old name with
- -ifl -> This is the ignored Files represented as a string of a list (like "[test.py, x.bat]")
- -ie -> This is the ignored extensions represented as a string of a list (like "[.py, .exe, .pyc]")
- -ifd -> THis is the ignored Folders represented as a string of a list (like "[venv, node_modules]")
Hren Works in the particular directory that you call it from.
- Basic Rename (Converts all instances of Test to Rest)
hren -o Test -n Rest
- Ignore Complete Folders (ignores folders named venv/ node_modules and lib/ and its contents)
hren -o Test -n Rest -ifd "[venv, node_modules, lib]"
- Ignore Certain Files (ignores files named test.py and hello.js)
hren -o Test -n Rest -ifl "[hello.js, test.py]"
- Ignore all files with particular file extensions (ignores files with .pyc and .exe extension)
hren -o Test -n Rest -ie "[.pyc, .exe]"
You can combine these arguements in any way you like!
- You cannot run this script inside a folder that you want to rename. For example, If youre in a folder named Test/ and inside it you change Test/ to Rest/ It will fail as it cannot access the folder when it is open in the commandline. To perform that action you must go one directory above and then run the command
- You cannot run this script directly in a drive volume for example: You cant run this script for a folder located in C: or E:, F: etc. It must be run inside a folder (This is because, the program will go through the entire folder structure, and since your system volume drives have so much data, it will take forever
- You must not be inside a folder name that you want to rename to. For example, if youre in a folder named Rest and you want to change Test to Rest, you cant do that while youre inside Rest. You must go one level up!
These are bugs and i will fix them at some point! If you can contribute feel free to do so!