Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Naomi K
Naomi K am 5 Nov. 2017
Beantwortet: Walter Roberson am 5 Nov. 2017
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'.

Antworten (1)

Walter Roberson
Walter Roberson am 5 Nov. 2017
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() ?

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by