exist() absolute vs relative path
33 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 8 Apr 2020
Modificato: Stephen23
il 8 Apr 2020
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?
Risposte (1)
Sean de Wolski
il 8 Apr 2020
If you're on a newer release, consider using isfile(). https://www.mathworks.com/help/matlab/ref/isfile.html
6 Commenti
Stephen23
il 10 Apr 2020
"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
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!