{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":70203,"databundleVersionId":8068726,"sourceType":"competition"}],"dockerImageVersionId":30702,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfrom collections import defaultdict\n\ndef find_duplicate_filenames(root_dir):\n    files_dict = defaultdict(list)\n    \n    # Walk through all directories and subdirectories\n    for subdir, dirs, files in os.walk(root_dir):\n        for file in files:\n            # Append the path of the file to the list of paths with the same file name\n            file_path = os.path.join(subdir, file)\n            files_dict[file].append(file_path)\n    \n    # Filter out file names with only one path (unique files)\n    duplicates = {file: paths for file, paths in files_dict.items() if len(paths) > 1}\n    \n    return duplicates\n\n# Example usage\nroot_directory = '/kaggle/input/birdclef-2024/train_audio'\nduplicates_by_name = find_duplicate_filenames(root_directory)\n\n# Print duplicates and their paths\nfor filename, paths in duplicates_by_name.items():\n    print(f\"Duplicate Filename: {filename}\")\n    for path in paths:\n        print(f\"  Found at: {path}\")\n    print(\"\\n\")  # Newline for better readability\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-22T08:48:45.150472Z","iopub.execute_input":"2024-04-22T08:48:45.151868Z","iopub.status.idle":"2024-04-22T08:48:45.508441Z","shell.execute_reply.started":"2024-04-22T08:48:45.151818Z","shell.execute_reply":"2024-04-22T08:48:45.507219Z"},"trusted":true},"execution_count":null,"outputs":[]}]}