GoodMorning, I ust want torun a script where it could give a value of zero if the selected directory doesn't exist.
It could be:
if dir C:\a == 'not found'
B=0
else
B=1
end
Actually i wanted an errormessage tho show up in gui, but that I can do by myself. Thanks

 채택된 답변

Guillaume
Guillaume 2015년 3월 11일

1 개 추천

Use exist:
if exist('C:\a', 'dir')

추가 답변 (1개)

Stephen23
Stephen23 2015년 3월 11일

1 개 추천

Use exist and also check for the correct output value:
if exist('C:\a', 'dir')==7
See the documentation for the list of output values.

댓글 수: 2

Guillaume
Guillaume 2015년 3월 11일
Well, if you specify the 'kind' (as 'dir'), then the output is either 7 or 0. Hence you don't actually need the comparison.
it does not hurt to be explicit though.
Stephen23
Stephen23 2015년 3월 11일
편집: Stephen23 2015년 3월 11일
@Guillaume: agreed that it is not strictly required, but it might make the code a bit more robust to future code changes (poorly managed find-and-replace, for example).

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2015년 3월 11일

편집:

2015년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by