· Travis Rodgers · Programming · 2 min read
Python File Challenge | How Would You Code It?
Video
Here’s the video explanation for this challenge, with the solution.
Challenge
Your boss has tasked you with writing a script to get rid of duplicate files in a folder.
Your company has a script that runs daily and as a by-product creates some duplicate files (sure we should address that issue at the root, but let’s just play along 😊).
So you need to create a script that you can run periodically to remove duplicate files.
Here’s what the duplicate files look like:
Note that they all have ” copy” in them.
This may differ depending on your system, like if you use windows, but put some screenshots and other files in a folder and copy and paste multiple copies of them and then work with how your system renames duplicates.
Can you write a script (choose your language) that:
- Allows you to pass in a CLI argument for the folder path
- Filters for duplicates and lists all duplicate files out that will be deleted for the user to then be prompted to either confirm or cancel.
So the flow would be:
- The person running the script passes in the path via the CLI with the command to run the script
- It lists all the files out that will be deleted
- Then the user is prompted to either confirm these deletions or cancel. On confirm all files are deleted. On cancel, the program ends.
HOW WOULD YOU CODE IT?
Here’s an example of what it would look like in action.
Paste your solutions, screenshots, and questions below!