{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":" <div class=\"alert alert-success\"> \n        <h1 align=\"center\" style=\"color:darkcyan;\">Converting all the files in sgemnetations folder to .nii format</h1>  \n     \n</div>","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-07-31T13:33:21.522286Z","iopub.execute_input":"2023-07-31T13:33:21.52275Z","iopub.status.idle":"2023-07-31T13:33:21.53253Z","shell.execute_reply.started":"2023-07-31T13:33:21.522716Z","shell.execute_reply":"2023-07-31T13:33:21.53079Z"}}},{"cell_type":"code","source":"import os\nimport shutil\n\n# Source directory containing the files without extension\nsrc_directory = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/'\n\n# Destination directory where the NIfTI files will be copied with '.nii' extension\ndst_directory = '/kaggle/working/'\n\n# List all the files in the source directory\nfile_list = os.listdir(src_directory)\n\n# Initialize a counter to keep track of the number of files copied\nnum_files_copied = 0\n\nfor filename in file_list:\n    # Check if the file does not have an extension (you may need to adapt this condition if there are other files in the folder)\n    if '.' not in filename:\n        # Construct the source and destination paths for the file\n        src_file = os.path.join(src_directory, filename)\n        dst_file = os.path.join(dst_directory, f\"{filename}.nii\")\n        \n        # Copy the file with the '.nii' extension\n        shutil.copyfile(src_file, dst_file)\n        \n        # Increment the counter\n        num_files_copied += 1\n        \n        # Check if we have copied the first 50 files\n        if num_files_copied == 50:\n            break\n\nprint(\"Conversion of the first 50 files completed.\")","metadata":{"execution":{"iopub.status.busy":"2023-07-31T13:35:20.2597Z","iopub.execute_input":"2023-07-31T13:35:20.260104Z","iopub.status.idle":"2023-07-31T13:38:58.595916Z","shell.execute_reply.started":"2023-07-31T13:35:20.260071Z","shell.execute_reply":"2023-07-31T13:38:58.594763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-success\"> \n        <h1 align=\"center\" style=\"color:darkcyan;\">Here we will load the segemntation folder and assign it as .nii extension save it in output file</h1>  \n     \n</div>","metadata":{}}]}