File does not exist error....
21 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I am reading .hdf files from a folder, matlab reads some of the files and for the remaining files, it gives an error:
file xxx.hdf does not exist.
While i have re-checked the folder all files are there...
Thanks
2 件のコメント
Walter Roberson
2015 年 12 月 20 日
Please show your code.
Please also show the output of dir() applied to the file, and show the output of fileattrib() applied to the file.
回答 (2 件)
Image Analyst
2015 年 12 月 21 日
JB, try this:
folder = pwd; % Whatever
fullFilename = fullfile(folder, 'Stringname.txt')
if exist(fullFilename, 'file') == -1
% First filename does not exist.
% Try the other filename.
fullFilename2 = fullfile(folder, 'Stringname2.txt')
if exist(fullFilename2, 'file') == -1
% Neither file exists.
errorMessage = sprintf('Neither filename exists:\n%s\nor\n%s', fullFilename, fullFilename2);
uiwait(warndlg(warningMessage));
else
% The second filename exists.
fullFilename = fullFilename2;
end
end
0 件のコメント
Walter Roberson
2015 年 12 月 21 日
[~, name, ~] = fileparts(filename);
1 件のコメント
Image Analyst
2015 年 12 月 21 日
I think he says he's looking for two possible filenames: it might be either "xxx.hdf" or "xxx2.hdf". I suggest using dir() to find it.
allFileNames = dir('xxx*.hdf');
If there is only one, then the length of allFileNames will be exactly 1. If both of those files exist, or more, then length(allFileNames) will be 2 or more and then he'll have to decide which of the files to use.
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!