필터 지우기
필터 지우기

File does not exist error....

조회 수: 21 (최근 30일)
JB
JB 2015년 12월 20일
댓글: Image Analyst 2015년 12월 21일
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
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.
JB
JB 2015년 12월 21일
편집: JB 2015년 12월 21일
Sorry for inconvience, i found the mistake. I have another query.For e.g I have
filename='Stringname.txt' OR
filename='Stringname2.txt'
how can i read the name or name2 for the same variable filename. Note:A folder may have any of the filenames described above.
thanks alot

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
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

Walter Roberson
Walter Roberson 2015년 12월 21일
[~, name, ~] = fileparts(filename);
  댓글 수: 1
Image Analyst
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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by