Add a file that holds the last used data directory
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 22 Jul 2024 11:48:38 +0000 (13:48 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 22 Jul 2024 13:33:40 +0000 (15:33 +0200)
The function get_data_dir creates a (hidden) file with the path last
used. This makes it easier to use when run repeatedly.

.gitignore
Bubliny.m
get_data_dir.m [new file with mode: 0644]

index c1fca2871f237df5ce153895e1b9ce2052a5c782..bd5e9af335b1bd70dc605527d03e73ca88319b51 100644 (file)
@@ -3,3 +3,4 @@
 *.xls*
 *.csv
 Thumbs.db
+.last_path
index d863af3eb1b5a2aee731d70eb9adfb3f95f414bd..a833fe03abaee55d80d0e99ef7800cf457f9ad45 100755 (executable)
--- a/Bubliny.m
+++ b/Bubliny.m
@@ -9,8 +9,9 @@ clc;                                                                        % cl
 %%\r
 % User dialog for the data directory used for files\r
 \r
+DirectoryName = get_data_dir();\r
+\r
 %DirectoryPath='T:\00-Orvalho\Travnickova\Bubble column\';\r
-DirectoryName = uigetdir(pwd(), 'Select the data folder');           % returns the name and path of the file selected in the dialog box\r
 disp(['The data directory used for files is ', DirectoryName]);             % displays the name of selected file in Command Window\r
 \r
 DDirectory = dir(DirectoryName);                                            % Loads directories or subdirectories to struct FFiles(1).name, FFiles(1).folder, FFiles(1).date - i s casem\r
diff --git a/get_data_dir.m b/get_data_dir.m
new file mode 100644 (file)
index 0000000..40d7043
--- /dev/null
@@ -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