Find if a folder already exists and act depending on the result!!!
15 次查看(过去 30 天)
显示 更早的评论
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!!!
0 个评论
采纳的回答
Walter Roberson
2012-5-25
fn = fullfile('DWI_Liver_Analyzer/PRIMARY PATIENTS', handles.Fak_asthn);
if exist(fn, 'dir')
warning(....)
else
mkdir(fn)
end
更多回答(1 个)
Image Analyst
2012-5-25
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 个评论
Image Analyst
2012-5-25
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!