Last active
December 9, 2015 19:24
-
-
Save noelyahan/8c6c3a9239469f0ecc97 to your computer and use it in GitHub Desktop.
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
# run instructions : python rename_all.py folder_path start_file_prefix | |
# ex: python rename_all.py /home/xxx/Pictures/my_collection "Garden-" | |
# output will be "Garden-1.png, Garden-2.png" etc.. | |
import sys | |
import os | |
# input arguments folder_path & rename prefix | |
args = sys.argv | |
# folder path which files are contains | |
folder_path = args[1] | |
# rename prefix | |
rename_prefix = args[2] | |
# file names list | |
file_names = [] | |
# preprocess variables | |
if folder_path[-1] != "/": | |
folder_path += "/" | |
# search for the files | |
for dir_path, sub_dir_list, file_list in os.walk(folder_path): | |
for fname in file_list: | |
# add file path to list for sorting purpose | |
file_names.append(fname) | |
# sort all the file names | |
file_names.sort() | |
# rename all | |
enum = 0 | |
for f in file_names: | |
enum += 1 | |
# organize the new name with the file extension | |
new_name = rename_prefix + str(enum) + f[f.index("."):] | |
# orgabnize the file name with full paths | |
old_file_name = folder_path + f | |
new_file_name = folder_path + new_name | |
#rename the file | |
os.rename(old_file_name, new_file_name) | |
print "----- RENAME PROCESS IS DONE !! ----" | |
print "+++ THANKS FOR USING THIS RENAME APP +++" | |
print ">>>> author @noelyahan <<<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment