-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e1ee97
Showing
4 changed files
with
378 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
output/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023-2024 TnyavnTo/Svxy/Sneaky | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,90 @@ | ||
<h3 align="center"><img src='https://github.com/Svxy/imgs/blob/main/DupliSweep/DupliSweep-dark.png?raw=true' style='width: 25%; height: auto;'><br><b>DupliSweep</b><br><sup><i>by Sneaky</i></sup></h3> | ||
|
||
<br> | ||
|
||
<p align="center"> | ||
<em>A simple and easy solution for finding and removing duplicate files.</em> | ||
</p> | ||
|
||
<br> | ||
|
||
<p align=center><em>Download the <a href=''>latest release</a>!</em></p> | ||
|
||
<br> | ||
|
||
## Table of Contents | ||
|
||
- [Introduction](#introduction) | ||
- [Features](#features) | ||
- [Getting Started](#getting-started) | ||
- [Cloning the Repository](#cloning-the-repository) | ||
- [Contributing](#contributing) | ||
- [Compiling with auto-py-to-exe](#compiling-with-auto-py-to-exe) | ||
- [Copyright](#copyright) | ||
|
||
## Introduction | ||
|
||
DupliSweep is a simple and user-friendly application aimed at helping users find and remove duplicate files on their computer. Whether it's duplicate photos, music files, or other types of files cluttering your storage space, DupliSweep saves you time and effort by providing a comprehensive solution to clean up your file system. | ||
|
||
DupliSweep allows you to easily scan specific folders or directories to identify duplicate files based on criteria such as file size and hash values, thus deeming filenames irrelevent. The tkinter based user interface allows you to preview and select duplicate files for removal, freeing up valuable disk space. | ||
|
||
## Features | ||
|
||
- Intuitive and user-friendly interface. | ||
- Flexible scanning options for customizing the search criteria. | ||
- Real-time progress updates during the scanning process. | ||
- Preview duplicate files before taking any action. | ||
- Remove selected duplicate files with a single click. | ||
- Support for various file types, including documents, images, music, and more. | ||
|
||
## Getting Started | ||
|
||
### Cloning the Repository | ||
|
||
To clone the DupliSweep repository and get the application up and running locally, follow these steps: | ||
|
||
1. Open a terminal or command prompt. | ||
2. Change the current working directory to the location where you want the project to be cloned. | ||
3. Run the following command: | ||
|
||
```console | ||
git clone https://github.com/svxy/duplisweep.git | ||
``` | ||
|
||
4. Navigate to the cloned repository: | ||
|
||
```console | ||
cd duplisweep | ||
``` | ||
|
||
### Contributing | ||
|
||
I more than welcome any contributions to enhance DupliSweep and make it even better. To contribute, please just be sure to follow these guidelines: | ||
|
||
1. Fork the repository on GitHub. | ||
2. Create a new branch from the `main` branch for your feature or bug fix. | ||
3. Commit your changes and push the branch to your forked repository. | ||
4. Submit a pull request with a detailed description of your changes. | ||
|
||
### Compiling with auto-py-to-exe | ||
|
||
If you want to compile DupliSweep into a standalone executable using auto-py-to-exe, follow these steps: | ||
|
||
1. Install and run the auto-py-to-exe script: | ||
|
||
```console | ||
pip install auto-py-to-exe | ||
``` | ||
|
||
```console | ||
auto-py-to-exe 'OR' python -m auto_py_to_exe | ||
``` | ||
|
||
2. Customize the settings to your needs within the GUI. | ||
3. Click "Convert .py to .exe" to compile the application. | ||
|
||
Note that additional instructions and troubleshooting for auto-py-to-exe can be found in their official documentation if needed. | ||
|
||
## Copyright | ||
|
||
Copyright © 2023 Sneaky<br>This project is licensed under the [MIT License](LICENSE). |
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,266 @@ | ||
import os | ||
import hashlib | ||
import threading | ||
import tkinter as tk | ||
from tkinter import ttk | ||
from tkinter import filedialog | ||
from tkinter import messagebox | ||
import datetime | ||
import webbrowser | ||
|
||
|
||
class ProgressPopup(tk.Toplevel): | ||
def __init__(self, master): | ||
super().__init__(master) | ||
self.title("Sweeper") | ||
|
||
self.progress_label = ttk.Label(self, text="Indexing files...", style='Custom.TLabel') | ||
self.progress_label.pack(padx=10, pady=10) | ||
|
||
self.folder_list = tk.Listbox(self, width=60, height=10) | ||
self.folder_list.pack(padx=10, pady=(0, 10)) | ||
|
||
self.indexed_files_label = ttk.Label(self, text="Indexed Files: 0", style='Custom.TLabel') | ||
self.indexed_files_label.pack(padx=10, pady=(0, 10)) | ||
|
||
self.progress_var = tk.DoubleVar() | ||
self.progress_bar = ttk.Progressbar(self, variable=self.progress_var) | ||
self.progress_bar.pack(padx=10, pady=(0, 10), fill=tk.X) | ||
|
||
def set_progress_label(self, text): | ||
self.progress_label.configure(text=text) | ||
|
||
def add_folder(self, folder_path): | ||
self.folder_list.insert(tk.END, folder_path) | ||
|
||
def update_indexed_files_label(self, count): | ||
self.indexed_files_label.configure(text=f"Indexed Files: {count}") | ||
|
||
def set_progress(self, value): | ||
self.progress_var.set(value) | ||
|
||
|
||
class DupliSweep: | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.title("DupliSweep - by Sneaky / TnyavnTo") | ||
self.root.configure(bg="dark red") | ||
|
||
# frame to hold the folder selection button | ||
folder_frame = ttk.Frame(self.root, padding=(15, 15, 15, 0), style='Custom.TFrame') | ||
folder_frame.pack(fill=tk.X) | ||
|
||
# button to select a folder | ||
select_folder_button = ttk.Button(folder_frame, text="Select Folder", command=self.select_folder) | ||
select_folder_button.pack(side=tk.LEFT) | ||
|
||
# label to display the selected folder path | ||
self.folder_label = ttk.Label(folder_frame, text="No folder selected", style='Custom.TLabel') | ||
self.folder_label.pack(side=tk.LEFT, padx=(15, 0)) | ||
|
||
separator = ttk.Separator(self.root, orient=tk.HORIZONTAL) | ||
separator.pack(fill=tk.X, pady=10) | ||
|
||
# frame to hold the treeview | ||
treeview_frame = ttk.Frame(self.root) | ||
treeview_frame.pack(fill=tk.BOTH, expand=True) | ||
|
||
# treeview to display the folder structure and duplicate files | ||
self.treeview = ttk.Treeview(treeview_frame) | ||
self.treeview.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) | ||
|
||
# scrollbars for the treeview | ||
vertical_scrollbar = ttk.Scrollbar(treeview_frame, orient=tk.VERTICAL, command=self.treeview.yview) | ||
vertical_scrollbar.pack(side=tk.RIGHT, fill=tk.Y) | ||
self.treeview.configure(yscrollcommand=vertical_scrollbar.set) | ||
|
||
# treeview columns | ||
self.treeview['columns'] = ('Path', 'Size', 'Hash') | ||
self.treeview.column('#0', width=250, minwidth=80, anchor=tk.W) | ||
self.treeview.column('Path', width=350, minwidth=120, anchor=tk.W) | ||
self.treeview.column('Size', width=50, minwidth=80, anchor=tk.CENTER) | ||
self.treeview.column('Hash', width=150, minwidth=120, anchor=tk.W) | ||
|
||
# treeview headings | ||
self.treeview.heading('#0', text='Name', anchor=tk.W) | ||
self.treeview.heading('Path', text='Path', anchor=tk.W) | ||
self.treeview.heading('Size', text='Size', anchor=tk.CENTER) | ||
self.treeview.heading('Hash', text='Hash', anchor=tk.W) | ||
|
||
# frame to hold the buttons | ||
buttons_frame = ttk.Frame(self.root, padding=(15, 0, 15, 10), style='Custom.TFrame') | ||
buttons_frame.pack(fill=tk.X) | ||
|
||
# button to remove duplicates | ||
remove_duplicates_button = ttk.Button(buttons_frame, text="Remove Duplicates", command=self.remove_duplicates) | ||
remove_duplicates_button.pack(side=tk.RIGHT, pady=15) | ||
|
||
# button to open the source code link | ||
source_code_button = ttk.Button(buttons_frame, text="Source Code", command=self.open_source_code) | ||
source_code_button.pack(side=tk.LEFT, pady=15) | ||
|
||
# button to preview the selected duplicate file | ||
preview_button = ttk.Button(buttons_frame, text="Preview", command=self.preview_duplicate) | ||
preview_button.pack(side=tk.RIGHT, padx=10, pady=15) | ||
|
||
self.indexed_duplicates = set() | ||
self.file_dict = {} | ||
|
||
def select_folder(self): | ||
"""open a folder selection dialog and update the selected folder label.""" | ||
folder_path = filedialog.askdirectory() | ||
|
||
if folder_path: | ||
self.folder_label.configure(text=folder_path) | ||
threading.Thread(target=self.scan_folder, args=(folder_path,), daemon=True).start() | ||
|
||
def scan_folder(self, folder_path): | ||
"""scan a folder and find duplicate files based on selected criteria.""" | ||
self.treeview.delete(*self.treeview.get_children()) | ||
self.indexed_duplicates.clear() | ||
|
||
progress_popup = ProgressPopup(self.root) | ||
progress_popup.geometry("420x325") | ||
|
||
indexed_files = 0 | ||
progress_value = 0 | ||
total_files = 0 | ||
|
||
def update_progress_label(text): | ||
progress_popup.set_progress_label(text) | ||
self.root.update_idletasks() | ||
|
||
def update_indexed_files_label(count): | ||
progress_popup.update_indexed_files_label(count) | ||
self.root.update_idletasks() | ||
|
||
def update_progress(value): | ||
progress_popup.set_progress(value) | ||
self.root.update_idletasks() | ||
|
||
def populate_treeview(file_dict): | ||
# sort file_dict by hash value and mark duplicates with red | ||
for file_hash, duplicates in sorted(file_dict.items(), key=lambda x: x[0]): | ||
parent = '' | ||
for file, file_path, file_size, _ in duplicates: | ||
tags = () | ||
if len(duplicates) > 1: | ||
tags = ('red',) | ||
|
||
if parent == '': | ||
parent = self.treeview.insert('', 'end', text=file, values=(file_path, file_size, file_hash), | ||
tags=tags) | ||
else: | ||
self.treeview.insert(parent, 'end', text=file, values=(file_path, file_size, file_hash), | ||
tags=tags) | ||
|
||
def calculate_hash(file_path): | ||
sha256_hash = hashlib.sha256() | ||
with open(file_path, "rb") as file: | ||
for chunk in iter(lambda: file.read(4096), b""): | ||
sha256_hash.update(chunk) | ||
return sha256_hash.hexdigest() | ||
|
||
def index_files(folder_path): | ||
nonlocal indexed_files, progress_value, total_files | ||
|
||
for root, _, files in os.walk(folder_path): | ||
update_progress_label(f"Indexing files in {root}") | ||
progress_popup.add_folder(root) | ||
update_indexed_files_label(indexed_files) | ||
|
||
for file in files: | ||
file_path = os.path.join(root, file) | ||
file_size = os.path.getsize(file_path) | ||
file_hash = calculate_hash(file_path) | ||
|
||
if file_hash in self.file_dict: | ||
self.file_dict[file_hash].append((file, file_path, file_size, root)) | ||
self.indexed_duplicates.add(file_hash) | ||
else: | ||
self.file_dict[file_hash] = [(file, file_path, file_size, root)] | ||
|
||
indexed_files += 1 | ||
progress_value = (indexed_files / total_files) * 100 | ||
update_progress(progress_value) | ||
|
||
# update treeview as files are indexed | ||
self.treeview.insert('', 'end', text=file, values=(file_path, file_size, file_hash)) | ||
self.treeview.update_idletasks() | ||
|
||
# auto scroll down the treeview | ||
self.treeview.yview_moveto(1) | ||
|
||
total_files = sum(len(files) for _, _, files in os.walk(folder_path)) | ||
|
||
threading.Thread(target=index_files, args=(folder_path,), daemon=True).start() | ||
|
||
self.root.wait_window(progress_popup) | ||
|
||
populate_treeview(self.file_dict) | ||
if indexed_files == total_files: | ||
messagebox.showinfo("Indexing Complete", f"Successfully Indexed {indexed_files} files.") | ||
else: | ||
messagebox.showinfo("Indexing Cancelled", "Indexing process was cancelled.") | ||
|
||
def preview_duplicate(self): | ||
"""preview the selected duplicate file.""" | ||
selected_item = self.treeview.focus() | ||
|
||
if selected_item: | ||
file_path = self.treeview.item(selected_item)['values'][0] | ||
if os.path.isfile(file_path): | ||
os.startfile(file_path) | ||
else: | ||
messagebox.showinfo("Error", "The file no longer exists.") | ||
|
||
def remove_duplicates(self): | ||
"""remove the selected duplicate files, keeping one copy of each duplicate.""" | ||
if not self.indexed_duplicates: | ||
messagebox.showinfo("Error", "No duplicates found. If you suspect this is a false output and that there are in fact duplicate files present, this could be due to their size and hash strings being different regardless of file content. This is a rare occurrence, but I would greatly appreciate feedback @SneakyV2_ on Twitter.") | ||
return | ||
|
||
deleted_count = 0 | ||
log_file_path = "sweep_results.txt" | ||
|
||
with open(log_file_path, "a") as log_file: | ||
log_file.write("DupliSweep Results - {}\n".format(datetime.datetime.now()) + "\n") | ||
|
||
for file_hash in self.indexed_duplicates: | ||
duplicates = self.file_dict[file_hash] | ||
# keep the first duplicate, remove the rest | ||
for i in range(1, len(duplicates)): | ||
_, file_path, _, _ = duplicates[i] | ||
try: | ||
os.remove(file_path) | ||
log_file.write("File: {}\n".format(file_path)) | ||
deleted_count += 1 | ||
except OSError: | ||
pass | ||
|
||
log_file.write("\n") | ||
|
||
self.treeview.delete(*self.treeview.get_children()) | ||
self.indexed_duplicates.clear() | ||
messagebox.showinfo("Duplicates Removed", f"A total of {deleted_count} indexed duplicate files have been removed. A 'sweep_results.txt' file has been created with a list of deleted files.") | ||
|
||
def open_source_code(self): | ||
"""open the source code link in a web browser.""" | ||
webbrowser.open("https://github.com/svxy/DupliSweep") | ||
|
||
def main(): | ||
root = tk.Tk() | ||
root.geometry("1280x720") | ||
root.resizable(False, False) | ||
|
||
style = ttk.Style() | ||
style.configure('Custom.TLabel', foreground='white', background='dark red') | ||
style.configure('Custom.TFrame', background='dark red') | ||
style.configure('Red.Treeview', foreground='white', background='red') | ||
|
||
DupliSweep(root) | ||
|
||
root.mainloop() | ||
|
||
if __name__ == "__main__": | ||
main() |