필터 지우기
필터 지우기

How do I check the user inputted name in edit box is a folder or not ?

조회 수: 1 (최근 30일)
Naomi K
Naomi K 2017년 11월 5일
답변: Walter Roberson 2017년 11월 5일
I want a user to input the name. Then check that named folder exists or not. If exists then show warning message else create a folder of that name.
I have written a code but it is showing me some error
a = get(handles.Name,'String');
if isempty(a)
errordlg('ENTER FIELDS PROPERLY','Error')
return
else
if exist('C:\Users\naomi\Desktop\',a)
warndlg('EXIST');
return
else
mkdir('C:\Users\naomi\Desktop\'a)
end
end
Error using exist The optional second input to exist must be 'var', 'builtin', 'class', 'dir' or 'file'.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 5일
projectdir = 'C:\Users\naomi\Desktop';
a = get(handles.Name,'String');
if isempty(a)
errordlg('ENTER FIELDS PROPERLY','Error')
return
end
targetdir = fullfile( projectdir, a );
if exist(targetdir, 'dir')
warndlg('EXIST');
return
else
mkdir(targetdir)
end
Have you considered using uigetdir() ?

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by