Want to use a guide pushbutton to delete all files except some in folder which gui is residing.
7 views (last 30 days)
Show older comments
I have a code that uses Matlabs GUIDE and throughout the process many .m, .mat, .png content is created and stored in the folder where the GUI resides. I have created a pushbutton that when pressed restarts the process but I also would like it to delete All but specific specified files that have names that do not change. For example the project Folder contains: Project1.m, project1.fig, HelpMakeProjectWork.m, pic.png, Creation.m, Creation2.mat.... Then delete all besides the first three listed needed files.
Thank you so much
0 Comments
Accepted Answer
Geoff Hayes
on 10 Jan 2017
Tessa - rather than mixing files that persist with those that are temporary, why not create a TEMP directory and save all of those temporary files to it? That way, when you push the button on your GUI, you could just remove that TEMP directory and all of its files. The TEMP directory can be a sub-directory/folder from your parent one (that where you have your Project1.m, Project1.fig, and HelpMakeProjectWork.m files) and you could delete it as
function pushbutton1_Callback(hObject, eventdata, handles)
if isfield(handles, 'tempDirectory')
rmdir(handles.tempDirectory,'s');
end
The above assumes that you have updated the handles structure with a path to the temporary directory. You can do this from within the OpeningFcn of your GUI as
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
tempDir = fullfile(pwd,'TEMP');
status = mkdir(tempDir);
if status
handles.tempDirectory = tempDir;
end
guidata(hObject,handles);
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps 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!