exist() absolute vs relative path
조회 수: 28 (최근 30일)
이전 댓글 표시
I was trying to check for existence of a file defined by absolute path and bumped into a strange behavior.
- If I define the file name with absolute path and without extension and the file is in the current folder exist() finds the file
- If I define the file name with absolute path and without extension and the file is NOT in the current folder exist() does NOT find the file
- If I define the file name with absolute path and with extension and the file is NOT in the current folder exist() does find the file
Is this the expected behavior?
My expectation would be that exist() still finds the file in case 2 OR exist does not find it in case 1 and 2.
댓글 수: 2
Stephen23
2020년 4월 8일
편집: Stephen23
2020년 4월 8일
Although the title of your question is "exist() absolute vs relative path", all of your examples use absolute paths.
I do not see that behavior on R2012b, exist works as expected and documented:
>> F1 = 'C:\Users\stephen.cobeldick\test.txt';
>> F2 = 'C:\Users\stephen.cobeldick\testnoext';
>> fclose(fopen(F1,'wt'));
>> fclose(fopen(F2,'wt'));
>> exist(F1,'file')
ans =
2
>> exist(F2,'file')
ans =
2
As you do not show the exact code that you tried we cannot comment on your attempt. It is possible that you did not specify the second argument, in which case I would not have high expectations of getting a useful output.
What version of MATLAB are you using?
답변 (1개)
Sean de Wolski
2020년 4월 8일
If you're on a newer release, consider using isfile(). https://www.mathworks.com/help/matlab/ref/isfile.html
댓글 수: 6
Stephen23
2020년 4월 10일
"This is still case 1 and 2 from my original question."
Yes, I agree that this deserves clarification from TMW. Note that TMW might have an easter break, so it could be worth bumping this thread next week to get attention from Sean de Wolski.
Otherwise you could:
- email them directly (see "Contact Us" at the top of the page), with a link to this thread, or
- create a bug report: https://www.mathworks.com/support/bug_reports/faq.html
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!