what is the output type of a nagative fullfill function result
1 次查看(过去 30 天)
显示 更早的评论
Hi Guys
I am using the fullfill function as followig :
dat_dir = fullfile(uigetdir ('select the subfolder for dat file'), '*.txt' );
if convertCharsToStrings(dat_dir) ~= " \*.txt"
dat= dir(dat_dir);
end
this will help me in other way , if i did not select the subfolder , to check the result of fullfile(uigetdir ('select the subfolder for dat file'), '*.txt' ) which i found \*.txt .
The problem in other words , i found that convertCharsToStrings(dat_dir) in the workspace is equal to " \*.txt" but when i debug it i found it is not equal to " \*.txt".
this is the error msg
Error using dir
Invalid path. The path must not contain a null character.
How should i test the negative result of fullfile function ? And why the if convertCharsToStrings(dat_dir) == " \*.txt" is return 0 although i can see in the workspace convertCharsToStrings(dat_dir) equal to " \*.txt"
采纳的回答
Jan
2021-11-9
What is the purpose of the leading space in " \*.txt"?
What does "if i did not select the subfolder" mean? Which subfolder? Do you mean, that you press 'Cancel' in the dialog? Then uigetdir() does not reply a space, but a numerical 0. Do not use a 0 as input for fullfile.
folder = uigetdir('select the subfolder for dat file');
if ~ischar(folder) % User pressed the Cancel button
folder = cd; % Is this wanted? Or: return?
end
dat = dir(fullfile(folder, '*.txt'));
Does this work as wanted?
3 个评论
Jan
2021-11-10
in the above code ~ischar(folder) means the user did not press ok
Yes, if the user presses "Cancel", uigetdir replies a numerical 0.
The code of your former comment looks fine. Then dat remains undefined, if the user has pressed cancel. If you care for this case, the code should run.