Analyse files in a different folder than current folder
Show older comments
Hi all!
For my GUI that analyses data files, the scripts are in the current folder. The data files that need to be analysed are in a separate folder. This folder is selected by the user beforehand using uigetdir. However, when I want another callback to find a specific file in that folder, it gives me an error because it is not searching in the right folder.
foldername = handles.foldername; %gets foldername from Choosefolder_Callback
str = char(get(handles.edit1, 'String')); %gets user input from edit1 textbox
S = dir(sprintf('*%s*',str))); %finds filename that matches user input
N = {S(~[S.isdir]).name}; %puts filenames in cell array
idx = ~cellfun('isempty',regexp(N,'^ID\w\d+sec\.csv$')); %indices of filenames which match regular expression
if nnz(idx)==1 % ensures the 1 filename match
filename = N{idx}; %get filename
indivtxt = sprintf('File has been located');
set(handles.text7, 'String', indivtxt); %sets string to individual data file selected
else
warningMessage = sprintf ('Warning: file does not exist\n%s');
uiwait(msgbox(warningMessage, 'Error', 'error'));
end
Why does this only work when I select the data files folder as my current folder and how can I change this? I need the current folder to be the scripts that I need for my GUI
Accepted Answer
More Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!