From 598a6a1f270e65b2981819374a44ca4e39e045d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Mon, 22 Jul 2024 13:48:38 +0200 Subject: [PATCH] Add a file that holds the last used data directory The function get_data_dir creates a (hidden) file with the path last used. This makes it easier to use when run repeatedly. --- .gitignore | 1 + Bubliny.m | 3 ++- get_data_dir.m | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 get_data_dir.m diff --git a/.gitignore b/.gitignore index c1fca28..bd5e9af 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.xls* *.csv Thumbs.db +.last_path diff --git a/Bubliny.m b/Bubliny.m index d863af3..a833fe0 100755 --- a/Bubliny.m +++ b/Bubliny.m @@ -9,8 +9,9 @@ clc; % cl %% % User dialog for the data directory used for files +DirectoryName = get_data_dir(); + %DirectoryPath='T:\00-Orvalho\Travnickova\Bubble column\'; -DirectoryName = uigetdir(pwd(), 'Select the data folder'); % returns the name and path of the file selected in the dialog box disp(['The data directory used for files is ', DirectoryName]); % displays the name of selected file in Command Window DDirectory = dir(DirectoryName); % Loads directories or subdirectories to struct FFiles(1).name, FFiles(1).folder, FFiles(1).date - i s casem diff --git a/get_data_dir.m b/get_data_dir.m new file mode 100644 index 0000000..40d7043 --- /dev/null +++ b/get_data_dir.m @@ -0,0 +1,24 @@ +function dir_path = get_data_dir() + if (isfile('.last_path')) + file_id = fopen('.last_path', 'r'); + last_path = char(fread(file_id))'; + fclose(file_id); + dir_path = uigetdir(last_path, 'Select the data folder'); + if ispc + fileattrib('.last_path', '-h'); + end + else + dir_path = uigetdir(pwd(), 'Select the data folder'); + end + + if dir_path == 0 + return + end + + file_id = fopen('.last_path', 'w'); + fprintf(file_id, "%s", dir_path); + fclose(file_id); + if ispc + fileattrib('.last_path', '+h'); + end +end -- 2.30.2