Trouble with code to check for Excel file existence

조회 수: 5 (최근 30일)
Douglas Anderson
Douglas Anderson 2012년 6월 4일
Hello!
xlsread() goes through a bunch of machinations before it tells you that the file doesn't exist if you mistyped the file name. I wrote the simple script to check if the file exists:
while exist('file_name','file') ~= 2
filename_root = input('File name (no xlsx)','s');
file_name = [filename_root,'.xlsx'];
end
disp('Success');
This way I could simply loop to correct an obvious misspelling. This doesn't work. I tried this:
filename_root = input('File name (no xlsx)','s');
file_name = strcat(filename_root,'.xlsx');
if exist('file_name','file') == 0
disp('Not found');
else
disp('Success');
end
and never got to "Success". Any thoughts?
Thanks!
Doug A

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 4일
if exist(file_name,'file') == 0

추가 답변 (1개)

Douglas Anderson
Douglas Anderson 2012년 6월 4일
One quick comment: I know that it isn't a path problem

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by