Saving all tabs into a folder

This question is about the interface. I would like to save all my Matlab script tabs into a folder. Is there any quick way to do that? Unfortunately, I cannot save them one by one since I do have 100+ scripts.
Thanks.

4 个评论

To check, are you referring to the editor?
If so, are these files that have already been saved, but you are wanting to make copies in a different folder?
Or are these files that either have never been saved or have been modified, and you are wanting to save the current versions to a particular folder?
Question: what is your setting for Preferences -> Editor/Debugger -> Automatic file changes -> Save changes upon clicking away from a file
Yes, it is the editor.
These files have already been saved. I would like to make copies as you pointed out.
My current Editor/Debugger settings are default and "Save changes upon clicking away from a file" is checked.
Briefly, I would like to bring all my editor scripts together in a file directory either by saving a copy or even moving if its possible.
Are you using the words script and function interchangeably? Because 100+ scripts is very likely to be a sign of terrible design. You should use functions to make sure you have a stable interface that you can document and can improve in isolation.
No, I've been coding for some time (about 6 years) and I just shrink tabs as I need those time to time, instead of closing. I'm not an expert neither as you can guess. I should have used more functions though, thats true.

请先登录,再进行评论。

 采纳的回答

targetdir = 'DirectoryToSaveInto';
if ~isdir(targetdir); mkdir(targetdir); end
X = matlab.desktop.editor.getAll;
newnames = fullfile(targetdir, {X.Filename}.');
arrayfun(@(Info, NewName) Info.saveAS(NewName), X, newnames)
You might need to 'Uniform', 0. You might possibly need to loop. And you might possibly need to deal specially with untitled

1 个评论

Thats great! I cannot thank you enough. Here's the syntax corrected running version for people need it.
targetdir = 'DirectoryToSaveInto';
if ~isdir(targetdir); mkdir(targetdir); end
X = matlab.desktop.editor.getAll;
newnames = fullfile(targetdir, {X.Filename}.');
[folder, baseFileNameNoExt, extension] = fileparts(newnames);
Fileswithextensions = strcat(baseFileNameNoExt,extension);
correctednames = fullfile(targetdir, Fileswithextensions.');
arrayfun(@(Info, NewName) Info.saveAs(NewName), X, correctednames)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Adding custom doc 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by