· Travis Rodgers · Programming  · 2 min read

Python File Challenge | How Would You Code It?

This is an interactive post! Challenge yourself to code the solution and post it below!

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!
    Share:

    Related Posts

    View All Posts »
    5 Steps to Learn React in 2025

    5 Steps to Learn React in 2025

    React is one of the most popular front-end JavaScript libraries. Let's break down the essential steps to learn React in 2025.

    5 Reasons Laravel is Trending in 2024

    5 Reasons Laravel is Trending in 2024

    In this article, I want to give 5 reasons why I think many more people are finding a newfound enjoyment or a re-found enjoyment in the Laravel ecosystem.