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

25 views (last 30 days)
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!!!

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2012
fn = fullfile('DWI_Liver_Analyzer/PRIMARY PATIENTS', handles.Fak_asthn);
if exist(fn, 'dir')
warning(....)
else
mkdir(fn)
end
  1 Comment
Paraskevas Papanikolaou
Paraskevas Papanikolaou on 25 May 2012
thank you very much it seems to work with some small changes !!!!!!!!!!
i will upload later my code

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 25 May 2012
My code snippet here will help you turn off that warning:
% Turn off this warning "Warning: Image is too big to fit on screen; displaying at 33% "
% To set the warning state, you must first know the message identifier for the one warning you want to enable.
% Query the last warning to acquire the identifier. For example:
% warnStruct = warning('query', 'last');
% messageID = warnStruct.identifier
% messageID =
% MATLAB:concatenation:integerInteraction
warning('off', 'Images:initSize:adjustingMag');
  2 Comments
Paraskevas Papanikolaou
Paraskevas Papanikolaou on 25 May 2012
Thanks Image Analyst but i dont want just to turn off that warning ,i would like to inform the user if he is using a name for a folder that already exists!!Moreover the warning that Matlab generates doesnt have a msg_id. Perhaps i can turn off the warning and check the names of the folders with another way /another function?....ANY IDEAS?
Image Analyst
Image Analyst on 25 May 2012
The just use exist(yourFolderName, 'dir') to see if the folder exists and warn the user that the folder exists already (though I wouldn't do that - I'd just continue on silently without telling the user):
if exist(yourFolderName, 'dir')
warningMessage = sprintf('The folder %s already exists!', yourFolderName);
uiwait(warndlg(warningMessage));
else
mkdir(yourFolderName);
end

Sign in to comment.

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!