Last active
June 7, 2018 06:30
-
-
Save alilosoft/bab07e23c4b4d4d0f854b96e26ffe6c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def rename_files(): | |
working_dir = os.getcwd() | |
print "Current Working Directory: " + working_dir | |
secret_msg_dir = working_dir + "/secret" | |
# list file_list in dir | |
file_list = os.listdir(secret_msg_dir) | |
# rename each file | |
os.chdir(secret_msg_dir) | |
print "Current Working Directory Changed to: " + os.getcwd() | |
for file_name in file_list: | |
new_file_name = file_name.translate(None, "0123456789") | |
os.rename(file_name, new_file_name) | |
# printing a nice report | |
file_name = " " * (25 - len(file_name)) + file_name | |
print file_name, "------ renamed to --------> ", new_file_name | |
rename_files() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my enhanced version of rename_files() function, defined in Secret_Message Mini-Project (1MAC Full Stack Course @Udacity.com).
Note that I'm using a relative directory for the 'secret' folder, instead of fixed one, to make the program portable, so any one can run it without any modification.
All what you have to do is to put the folder 'secret' containing the secret message in the same directory as the python file secret_message.py and run it, to reveal the secret ;), have fun.