フィルターのクリア

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 Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by