From: Lukáš Jiřiště Date: Mon, 14 Oct 2024 09:08:55 +0000 (+0200) Subject: Refactor last_path handling out of get_data_dir X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=556eebfa837dbc403a581402ff3f9237cea1bb92;p=Bubble_column.git Refactor last_path handling out of get_data_dir This is done so that the logic can be used with function other than uigetdir (eg. uigetfile) --- diff --git a/get_data_dir.m b/get_data_dir.m index 40d7043..82b7c4b 100644 --- a/get_data_dir.m +++ b/get_data_dir.m @@ -1,24 +1,8 @@ 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 + dir_path = uigetdir(get_last_path(), 'Select the data folder'); 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 + update_last_path(dir_path) end diff --git a/get_last_path.m b/get_last_path.m new file mode 100644 index 0000000..d9deab5 --- /dev/null +++ b/get_last_path.m @@ -0,0 +1,12 @@ +function last_path = get_last_path() + if (isfile('.last_path')) + file_id = fopen('.last_path', 'r'); + last_path = char(fread(file_id))'; + fclose(file_id); + if ispc + fileattrib('.last_path', '-h'); + end + else + last_path = pwd() + end +end diff --git a/update_last_path.m b/update_last_path.m new file mode 100644 index 0000000..7511e9d --- /dev/null +++ b/update_last_path.m @@ -0,0 +1,8 @@ +function update_last_path(last_path) + file_id = fopen('.last_path', 'w'); + fprintf(file_id, "%s", last_path); + fclose(file_id); + if ispc + fileattrib('.last_path', '+h'); + end +end