I want to delete in all notebooks in a certain root directory all output cells as well as all other output generated during evaluation (e.g. from print and other) and afterwards save the cleaned notebooks using the same names.
From here (Yves Klett) I borrowed some code:
CleanNotebook[nb_: SelectedNotebook[],
styles_: {"Output"}] := (NotebookFind[nb, #, All, CellStyle];
NotebookDelete[nb];) & /@ styles;
ChoiceDialog[{FileNameSetter[Dynamic[imageDir], "Directory"],
Dynamic[imageDir]}];
notebookFiles = FileNames["*.nb", imageDir, Infinity];
num = Length[notebookFiles];
Do[
file = notebookFiles[[i]];
nb = NotebookOpen[file, Visible -> False];
CleanNotebook[nb];
NotebookSave[nb, file];
NotebookClose[nb];
, {i, 1, num}
];
My problem: Output cells seem to be correctly deleted BUT output from e.g. Print
is not deleted. How can this be solved?