From: Lukáš Jiřiště Date: Mon, 22 Jul 2024 11:48:38 +0000 (+0200) Subject: Add a file that holds the last used data directory X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=598a6a1f270e65b2981819374a44ca4e39e045d8;p=Bubble_column.git 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. --- 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