random_rename

New Programmer

Program to to randomize filenames for blinded reviews

3 bonuses 7 hints 26 solved 6 reviews

I'd like you to write a command-line program that will assist in blinded review of job candidates.

This script, random_rename.py should accept a directory of .py files and randomly copy those files to a new directory. Initially your program just needs to print out the expected output (but not actually copy anything).

Given this directory, /home/trey/job candidates 3000:

job candidates 3000
├── Ann Torres.py
├── Bryon Buffington.py
├── Courtney Williams.py
├── Erwin Troche.py
├── Ezra Costello.py
├── Gloria Guajardo.py
├── Tracy Swee.py
└── Whitney Paladino.py

If we pass this directory path to our random_rename.py program, it should print out the .py file names in the directory and the name of a new directory it will create (though it doesn't need to actually create it yet):

$ python3 random_rename.py "job candidates 3000"
Anonymizing:
job candidates 3000/Ann Torres.py
job candidates 3000/Bryon Buffington.py
job candidates 3000/Courtney Williams.py
job candidates 3000/Erwin Troche.py
job candidates 3000/Ezra Costello.py
job candidates 3000/Gloria Guajardo.py
job candidates 3000/Tracy Swee.py
job candidates 3000/Whitney Paladino.py
Saving files in new directory: /home/trey/job candidates 3000 anonymized

The new directory name should be the same as the original directory, but with anonymized on the end.

The filenames to anonymize should be printed as relative paths, based on what the user passed in as a command-line argument. The filenames should be printed in sorted order. Only files should be printed (not directories).

The directory to save files in should be printed as an absolute path.

Bonus 1


Trey Hunner

Want to solve this one?

Hi, I’m Trey, and I teach Python. Give this one a go, then I’ll show you how I’d solve it.

Sign up and solve it 7 days of All Access, no card needed