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

1 次查看(过去 30 天)
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