Python practice: removing duplicate files

#! usr/bin/env python3
# find duplicates of a file specified by the user,
# in a directory specified by the user

import os, sys, filecmp

print("Enter location of the file of which you want to find duplicates of:")
location = input()

if not os.path.isfile(location):
    print("Enter the location of a file!")
    sys.exit()

fileName, fileExtension = os.path.splitext(location)

print("In which directory do you want to search for duplicate files?")
myLocation = input()

if not os.path.isdir(myLocation):
    print("Enter the address of a directory!")
    sys.exit()

for folderName, subfolders, filenames in os.walk(myLocation):
    for filename in filenames:
        if filename.endswith(fileExtension):
            if filecmp.cmp(location, os.path.join(folderName,filename)):
                print("FILES " + location + " and " + filename + " seem equal")
                print("Do you want to delete " + os.path.join(folderName,filename) + " ? (y/n)")
                choice = input()
                if choice == "y":
                    os.unlink(filename)
                    continue
                else:
                    continue

Comments about the code are welcome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s