Skip to content

Instantly share code, notes, and snippets.

@alilosoft
Last active June 7, 2018 06:30
Show Gist options
  • Save alilosoft/bab07e23c4b4d4d0f854b96e26ffe6c9 to your computer and use it in GitHub Desktop.
Save alilosoft/bab07e23c4b4d4d0f854b96e26ffe6c9 to your computer and use it in GitHub Desktop.
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()
@alilosoft
Copy link
Author

alilosoft commented Jun 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment