{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Caption files created successfully.\n" ] }, { "ename": "", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n", "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n", "\u001b[1;31mClick here for more info. \n", "\u001b[1;31mView Jupyter log for further details." ] } ], "source": [ "import os\n", "\n", "def create_caption_file(directory):\n", " for root, dirs, files in os.walk(directory):\n", " for file in files:\n", " if file.lower().endswith(('.jpg', '.jpeg', '.png')):\n", " image_path = os.path.join(root, file)\n", " caption_file = os.path.splitext(image_path)[0] + \".caption\"\n", " if not os.path.exists(caption_file):\n", " with open(caption_file, 'w'):\n", " pass\n", "\n", "if __name__ == \"__main__\":\n", " directory = r'C:\\Users\\kade\\Desktop\\training_dir_staging'\n", " create_caption_file(directory)\n", " print(\"Caption files created successfully.\")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }