我想制作一个gui,其中按下按钮时会搜索文件/文件夹,当它执行时会将该路径提供给另一个单独的函数,它将在获取路径后进行一些处理。到目前为止我做到了这个
function pushbutton2_Callback(hObject, eventdata, handles)
....
....
folder_name=uigetdir('File Selector');
此浏览文件夹,现在我想将该文件夹的路径提供给此功能
source_dir = 'here the path of that folder comes';
source_files = dir(fullfile(source_dir, '*.txt/etc'));
换句话说,如果我解释一下,我使用的按钮开始执行这个功能,但首先它选择一个文件/目录输入到该功能。我尝试使用一些例子但我是新手制作gui所以我还没有成功。任何帮助将不胜感激。谢谢。
编辑..
这就是我想要做的事情。
function pushbutton2_Callback(hObject, eventdata, handles)
...
folder_name=uigetdir('File Selector');
global folder_path
folder_path=genpath(folder_name);
%% ftn将在何处使用
function abc %% this function is also called in another function.
global folder_path
source_dir = folder_path; %%% where all the files are placed
src_files = dir(fullfile(source_dir, '*.txt'));
然后循环加载所有文件
答案 0 :(得分:0)
function pushbutton2_Callback(hObject, eventdata, handles)
folder_name=uigetdir('File Selector');
listFiles(folder_name);
end
% put this function in the generated m-file
function listFiles(folder_name)
source_files = dir(fullfile(folder_name, '*.txt/etc'));
% do something with the files
end