Clear Filters
Clear Filters

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

1 view (last 30 days)
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'.

Answers (1)

Walter Roberson
Walter Roberson on 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() ?

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!