Help with isempty and exists
조회 수: 21 (최근 30일)
이전 댓글 표시
Hello community,
I have a simple problem. I want to prompt the user to enter a directory name, check if it exist. If it does, store that fullpath into my guidedata. If it doesnt, create the directory and also 2 subdirectories within that directory then store fullpath into guide data. The name of the directory I want to search and create folders in is named 'Labelers.' It's fullpath is C:\Users\ecorbett\Documents\MATLAB\Labelers So far I have this code:
prompt = {'Enter Labeler Name:'};
dlg_title = 'Labeler Name';
num_lines = 1;
answer = inputdlg(prompt);
if isempty('Labelers'(answer))
mkdir('Labelers','answer')
else
handles.name = answer;
guidata(gcf, handles);
handles = guidata(gcf);
end
It's not working thus far. Any advice will be greatly appreciated!
댓글 수: 2
Image Analyst
2011년 8월 1일
Why don't you just call uigetdir to let the user specify a folder and create one if needed? The "New folder" button is right there on the dialog box.
채택된 답변
Oleg Komarov
2011년 8월 1일
root = 'C:\Users\Oleg\Desktop\';
answer = inputdlg(prompt);
if isempty(answer{1}) || exist([root answer{1}],'dir') ~= 7
mkdir(root,'answer')
else
handles.name = answer;
guidata(gcf, handles);
handles = guidata(gcf);
end
댓글 수: 12
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!