exist() absolute vs relative path
29 ビュー (過去 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!