From ad82bed68d7c11c98db35291e6a349b1d5689620 Mon Sep 17 00:00:00 2001 From: TheoLaudatQM <98808790+TheoLaudatQM@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:23:48 +0200 Subject: [PATCH] Create the root folder if it doesn't exist (#226) * Create the root folder if it doesn't exist * changelog * Add a message when the root folder is created * Improved message --- CHANGELOG.md | 3 +++ qualang_tools/results/data_handler/data_folder_tools.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aa8eb5c..6c3c03c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Added +- results - Allow the data saver to create the root folder if it doesn't exist. + ## [0.17.7] - 2024-08-20 ### Added - VoltageGateSequence - The `VoltageGateSequence` class facilitates the creation and management of complex pulse sequences, allowing dynamic voltage control, ramping, and bias compensation across gate elements. diff --git a/qualang_tools/results/data_handler/data_folder_tools.py b/qualang_tools/results/data_handler/data_folder_tools.py index 725d2d21..171d2c69 100644 --- a/qualang_tools/results/data_handler/data_folder_tools.py +++ b/qualang_tools/results/data_handler/data_folder_tools.py @@ -108,7 +108,11 @@ def get_latest_data_folder( root_data_folder = Path(root_data_folder) if not root_data_folder.exists(): - raise NotADirectoryError(f"Root data folder {root_data_folder} does not exist.") + try: + root_data_folder.mkdir(parents=True) + print(f"The provided root folder didn't exist, so it was created at '{root_data_folder.absolute()}'.") + except (Exception,): + raise NotADirectoryError(f"Root data folder {root_data_folder} does not exist.") if current_folder_pattern is None: current_folder_pattern = folder_pattern