Last active
August 29, 2015 14:23
-
-
Save jamesrr39/b16656a5870f7eaf4e87 to your computer and use it in GitHub Desktop.
Find duplicate filenames within a path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
Tool to find files with the same name within a directory. | |
Developed to help with detection of unused files that weren't being detected as unused by require.js as they had the same names as other files that were being imported. | |
usage: | |
python find-duplicate-filenames.py [path] | |
options: | |
path: path on which to look. Defaults to the current working directory. | |
''' | |
import os | |
import sys | |
rootPath = sys.argv[1] if len(sys.argv) >= 2 else "." | |
filenames = {} | |
for root, dirs, files in os.walk(rootPath): | |
for file in files: | |
if filenames.has_key(file): | |
filenames[file].append(os.path.join(root, file)) | |
else: | |
filenames[file] = [os.path.join(root, file)] | |
for filename in filenames: | |
filepaths = filenames[filename] | |
if len(filepaths) > 1: | |
print filename + " duplicated at:" | |
for filepath in filepaths: | |
print filepath.replace(rootPath, "", 1) | |
print "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment