-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from NYPD/v0.0.1
V0.0.1
- Loading branch information
Showing
6 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,10 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
### VisualStudioCode ### | ||
.vscode | ||
.history | ||
|
||
# Pycharm | ||
.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
# Phodupe | ||
# phodupe | ||
|
||
## What is it | ||
|
||
A simple little python script that finds duplicate file names (without the extension) across two directories and gives the user the option to delete them. | ||
|
||
## Why | ||
|
||
I used this as an opportunity to begin learning python. It was created for a very very specific scenario and might not be too useful to anyone else. | ||
|
||
## How do to install / run | ||
|
||
(There are probobly better ways to run this, but i'm a python noob) | ||
|
||
- Navigate to the folder you downloaded the git project to | ||
- cd \development\git\Phodupe\ | ||
- Install the python script | ||
- python .\setup.py install | ||
- Run the script by passing two directories | ||
- python phodupe "C:\Users\NYPD\Desktop\OG Phone Walls" "C:\Users\NYPD\Desktop\2Delete" |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sys | ||
from phodupe.dupe_finder import DupeFinder | ||
|
||
|
||
def main(): | ||
|
||
destination1 = sys.argv[1] | ||
destination2 = sys.argv[2] | ||
|
||
dupe_files = DupeFinder.getDuplicateFileNames(destination1, destination2) | ||
|
||
if len(dupe_files) is 0: | ||
print('No dupe files found!') | ||
exit() | ||
|
||
user_input = input("{} duplicate file names found. Enter 'y' to delete or 'n' to abort:\n".format(len(dupe_files))) | ||
|
||
if user_input == 'y': | ||
DupeFinder.deleteFiles(dupe_files, destination1, destination2) | ||
print('Files deleted, exiting...') | ||
else: | ||
print('No files deleted, aborting...') | ||
exit() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
import pathlib | ||
import glob | ||
import itertools | ||
|
||
class DupeFinder: | ||
""" | ||
Simple utility class for finding and manipulating duplicate files | ||
""" | ||
|
||
@staticmethod | ||
def getDuplicateFileNames(directory1, directory2): | ||
""" | ||
Return a list of duplicate file name "stems" in both directories. | ||
e.g. : | ||
directory1 : [a.png, b.png] | ||
directory2 : [a.png, b.png] | ||
returns: [a, b] | ||
Parameters | ||
---------- | ||
directory1 : str | ||
Path of the first directory | ||
directory2 : str | ||
Path of the second directory | ||
Returns | ||
------- | ||
list | ||
A list of the duplicate file names between both directories. If no | ||
duplicate files are found, an empty list is returned | ||
""" | ||
directory1Path = pathlib.Path(directory1) | ||
directory2Path = pathlib.Path(directory2) | ||
|
||
directory1FilesNoExt = [] | ||
directory2FilesNoExt = [] | ||
|
||
for file in os.listdir(directory1Path): | ||
purePath = pathlib.Path(os.path.join(directory1, file)) | ||
directory1FilesNoExt.append(purePath.stem) | ||
for file in os.listdir(directory2Path): | ||
purePath = pathlib.Path(os.path.join(directory2, file)) | ||
directory2FilesNoExt.append(purePath.stem) | ||
|
||
dupeFiles = [] | ||
|
||
for fileName in directory1FilesNoExt: | ||
if fileName in directory2FilesNoExt: | ||
dupeFiles.append(fileName) | ||
|
||
return dupeFiles | ||
|
||
@staticmethod | ||
def deleteFiles(fileNames, directory1, directory2): | ||
""" | ||
Deletes the files provided in both directories | ||
Parameters | ||
---------- | ||
fileNames : list | ||
List of string files names to delete | ||
directory1 : str | ||
Path of the first directory | ||
directory2 : str | ||
Path of the second directory | ||
""" | ||
for file in fileNames: | ||
|
||
directory1Path = os.path.join(directory1, file) | ||
directory2Path = os.path.join(directory2, file) | ||
|
||
directory1Glob = glob.glob('{}.*'.format(directory1Path)) | ||
directory2Glob = glob.glob('{}.*'.format(directory2Path)) | ||
|
||
for filePath in itertools.chain(directory1Glob, directory2Glob): | ||
os.remove(filePath) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='phodupe', | ||
version='v0.0.1', | ||
packages=['phodupe'], | ||
url='https://github.com/NYPD/phodupe', | ||
license='MIT', | ||
author='NYPD', | ||
description='Duplicate file finder' | ||
) |