{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":21755,"databundleVersionId":1475600,"sourceType":"competition"},{"sourceId":10206735,"sourceType":"datasetVersion","datasetId":6307748},{"sourceId":10338546,"sourceType":"datasetVersion","datasetId":6401840},{"sourceId":10343362,"sourceType":"datasetVersion","datasetId":6405082}],"dockerImageVersionId":30804,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport shutil\nfrom pathlib import Path\n\ndef count_and_copy_images():\n    # 源目录路径\n    source_path = Path(\"/kaggle/input/20250101\")\n    \n    # 目标目录路径\n    dest_path = Path(\"/kaggle/working/images_temp\")\n    \n    try:\n        # 创建目标目录\n        dest_path.mkdir(parents=True, exist_ok=True)\n        \n        # 获取所有JPG文件（包括.jpg和.jpeg）\n        jpg_files = list(source_path.glob(\"*.jpg\")) + list(source_path.glob(\"*.jpeg\"))\n        \n        # 打印JPG文件数量\n        print(f\"Found {len(jpg_files)} JPG files in {source_path}\")\n        \n        # 复制文件\n        print(\"Copying files...\")\n        for jpg_file in jpg_files:\n            shutil.copy2(jpg_file, dest_path / jpg_file.name)\n        print(f\"Successfully copied {len(jpg_files)} files to {dest_path}\")\n        \n        # 创建zip文件\n        zip_path = \"/kaggle/working/images\"\n        shutil.make_archive(zip_path, \"zip\", dest_path)\n        print(f\"Created zip file at: {zip_path}.zip\")\n        \n        # 清理临时目录\n        shutil.rmtree(dest_path)\n        print(\"Cleaned up temporary directory\")\n        \n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        \n    return len(jpg_files)\n\n# 执行函数\nnum_files = count_and_copy_images()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-16T04:55:21.670028Z","iopub.execute_input":"2024-12-16T04:55:21.670699Z","iopub.status.idle":"2024-12-16T04:55:59.095144Z","shell.execute_reply.started":"2024-12-16T04:55:21.670608Z","shell.execute_reply":"2024-12-16T04:55:59.093020Z"}},"outputs":[],"execution_count":null}]}