Skip to content
TheChatArchiveThe Chat Archive
OpenChatopenchat-3.5-0106· OpenChatHugging Face Arena Human Preference 55K

write python application with GUI to search dublicate files on local computer. With…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralnous-hermes-2-mixtral-8x7b-dpo’s answer.
  1. User

    write python application with GUI to search dublicate files on local computer. With ability on UI to choose which directory to analyse and save files as CSV

  2. OpenChat Assistant

    To create a Python application with a GUI to search for duplicate files on a local computer and save the results as a CSV file, you can use the Tkinter library for the GUI and the filehash library to find duplicate files. Here's a step-by-step guide to creating the application:

    1. Install the required libraries:
    pip install tkinter
    pip install filehash
    
    1. Create the main application file (duplicate_file_finder.py):
    import os
    import tkinter as tk
    from tkinter import filedialog, messagebox
    import csv
    import hashlib
    import fnmatch
    
    def find_duplicates(directory, extension):
        duplicates = {}
        for root, dirs, files in os.walk(directory):
            for file in files:
                if file.endswith(extension):
                    file_path = os.path.join(root, file)
                    file_hash = hashlib.md5(open(file_path, "rb").read()).hexdigest()
                    if file_hash in duplicates:
                        duplicates[file_hash].append(file_path)
                    else:
                        duplicates[file_hash] = [file_path]
        return duplicates
    
    def save_to_csv(duplicates, filename):
        with open(filename, "w", newline="") as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow(["File Hash", "File Path"])
            for hash_value, files in duplicates.items():
                for file_path in files:
                    writer.writerow([hash_value, file_path])
        messagebox.showinfo("Success", "CSV file saved successfully.")
    
    def browse_directory():
        global selected_directory
        selected_directory = filedialog.askdirectory()
        directory_label.config(text=selected_directory)
    
    def browse_extension():
        global selected_extension
        selected_extension = filedialog.askopenfilename()
        extension_label.config(text=selected_extension)
    
    def search_duplicates():
        extension = selected_extension.split(".")[-1].lower()
        duplicates = find_duplicates(selected_directory, f"*.{extension}")
        if duplicates:
            save_to_csv(duplicates, "duplicates.csv")
        else:
            messagebox.showinfo("No Duplicates Found", "No duplicate files found in the selected directory.")
    
    app = tk.Tk()
    app.title("Duplicate File Finder")
    
    directory_label = tk.Label(app, text="Select a directory")
    directory_label.pack()
    
    directory_button = tk.Button(app, text="Browse", command=browse_directory)
    directory_button.pack()
    
    extension_label = tk.Label(app, text="Select a file extension")
    extension_label.pack()
    
    extension_button = tk.Button(app, text="Browse", command=browse_extension)
    extension_button.pack()
    
    search_button = tk.Button(app, text="Search for Duplicates", command=search_duplicates)
    search_button.pack()
    
    app.mainloop()
    

    This application allows you to choose a directory and a file extension to search for duplicate files. Once you click the "Search for Duplicates" button, it will display a list of duplicate files in a CSV file.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.