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

write a code to search for duplicate files images and videos including sub folders and…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-2-70b-chat’s answer.
  1. User

    write a code to search for duplicate files images and videos including sub folders and create a new folder named lovebug to place all the duplicates in

  2. OpenChat Assistant

    import os import hashlib from pathlib import Path

    def get_file_hash(file_path): with open(file_path, 'rb') as file: file_data = file.read() return hashlib.md5(file_data).hexdigest()

    def find_duplicate_files(root_folder, lovebug_folder): duplicates = []

    for folder in [folder for folder in os.listdir(root_folder) if os.path.isdir(os.path.join(root_folder, folder))]:
        for sub_folder in [sub_folder for sub_folder in os.listdir(os.path.join(root_folder, folder)) if os.path.isdir(os.path.join(root_folder, folder, sub_folder))]:
            for file in [file for file in os.listdir(os.path.join(root_folder, folder, sub_folder)) if os.path.isfile(os.path.join(root_folder, folder, sub_folder, file))]:
                file_path = os.path.join(root_folder, folder, sub_folder, file)
                file_hash = get_file_hash(file_path)
    
                if any(os.path.join(lovebug_folder, duplicate_file) == file_path for duplicate_file in duplicates):
                    continue
    
                for other_file in duplicates:
                    other_file_hash = get_file_hash(os.path.join(lovebug_folder, other_file))
                    if file_hash == other_file_hash:
                        print(f"Duplicate found: {file_path}")
                        os.rename(file_path, os.path.join(lovebug_folder, file))
                        break
                else:
                    duplicates.append(file)
    
    return duplicates
    

    root_folder = '/path/to/your/folder' lovebug_folder = os.path.join(root_folder, 'lovebug') os.makedirs(lovebug_folder, exist_ok=True)

    find_

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