フィルターのクリア

How to check if a path exists

186 ビュー (過去 30 日間)
Jason Goad
Jason Goad 2013 年 9 月 11 日
コメント済み: Walter Roberson 2020 年 4 月 8 日
I generate a path from a table using syntax that I expect and I want to be able to check if the generated path is valid. If it is not I want to add one to the index. If it is, continue on as usual.
Thanks in advance.
  1 件のコメント
Jan
Jan 2013 年 9 月 12 日
The question is not clear. What does "path from a table" mean? It is expected, that you use the syntay you expect. But for a discussion of occurring problems it would be useful if you post it here also. How coulöd we know which kind of "path" you mean and what how "valid" is defined. To which "index" can "one" be added (is "one" a "path" or 1.0?)? Even "continue as usual" has a meaning for you, but we cannot have the faintest idea of what you are talking about.

サインインしてコメントする。

回答 (2 件)

dpb
dpb 2013 年 9 月 11 日
  3 件のコメント
Matt Kindig
Matt Kindig 2013 年 9 月 11 日
dpb
dpb 2013 年 9 月 12 日
編集済み: dpb 2013 年 9 月 12 日
Works just fine if given the fully-qualified directory name the OP has just created -- example here--
>> exist('c:\temp','dir')
ans =
7
>> exist('c:\junktemp','dir')
ans =
0
>>
As Matt K points out,
exist('A','dir')==7
is the same as
isdir('A')
It had slipped my mind TMW has wrapped it; might as well use the "syntactic sugar" since it is already there.

サインインしてコメントする。


Rishikesh Agrawani
Rishikesh Agrawani 2018 年 5 月 10 日
編集済み: Rishikesh Agrawani 2018 年 5 月 10 日
I have valid path to the Desktop as C:\Users\rishi\Desktop in my Windows 10 system.
Here, I have tried to check for the existence of path elements like C:\, C:\Users (i.e. Users directory), C:\Users\rishi (i.e. rishi directory) etc.
>> exist('C:\', 'dir')
ans =
7
>> exist('C:', 'dir')
ans =
7
>> exist('C:\Users', 'dir')
ans =
7
>> exist('C:\Users\', 'dir')
ans =
7
>> exist('C:\\Users\\', 'dir')
ans =
7
>> exist('C:\\Users', 'dir')
ans =
7
>> exist('C:\\User', 'dir')
ans =
0
>> exist('C:\\Users\rishi', 'dir')
ans =
7
>> exist('C:\\Users\RiShi', 'dir')
ans =
7
>> exist('C:\\Users\rishi\Desktop', 'dir')
ans =
7
>> exist('C:\\Users\rishi\Deskto', 'dir')
ans =
0
>> exist('C:\\Users\\rishi\\Desktop\\', 'dir')
ans =
7
>>
>> ret == 7
ans =
logical
1
>> if ret == 7
disp('Directory exists')
else
disp('Directory does not exist')
end
Directory exists
>>
  2 件のコメント
Mostafa Sanusi
Mostafa Sanusi 2020 年 4 月 8 日
The path 'F:\' does not exist
Trying to get the MATLAB working but got this message. how to solve this issue
Walter Roberson
Walter Roberson 2020 年 4 月 8 日
It sounds as if you do not have a drive label F: or a path mapped to F: either.
Does F: show up for you in Windows Explorer?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by