MATLAB: Find if a folder already exists and act depending on the result!!!

folderswarning

I ve created a GUI that generates some folders where some files are saved.The folder takes the name that user gives it .When the user creates a folder with the same name Matlab generates a warning .
.I would like to ask if there is a way to use this warning ?For example if the user create the same folder and there is a warning show a message let the user decide where to save the data and if not continue !! I ve tried to produce this kind of code (catch the warning) but with no results(i am afraid i am doing it wrong) ,so if someone has another idea on how I can check the name of the folders and just inform the user that has put the same name in the folder and then act i will be covered!!
Here is the code …the user press the pushbutton16. and depending on some radiobutton choices that he made creates the folder .So if the name of the folder has been use again a warning is generated in the line after mkdir : Warning: Directory already exists. (handles.Fak_asthn is the name of the folder )
% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h_selectedRadioButton = get(handles.uipanel21,'SelectedObject');
selectedRadioTag = get(h_selectedRadioButton,'tag');
switch selectedRadioTag
case 'radiobutton2'
mkdir('DWI_Liver_Analyzer/PRIMARY PATIENTS',handles.Fak_asthn)
Thanks in advance!!!

Best Answer

fn = fullfile('DWI_Liver_Analyzer/PRIMARY PATIENTS', handles.Fak_asthn);
if exist(fn, 'dir')
warning(....)
else
mkdir(fn)
end