From bd8dfa8edaf5899d82c0ae5f35c8a138eea158e5 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Mon, 25 Nov 2024 10:04:28 +0100
Subject: [PATCH] clean_current_folder.m: update and document command

---
 doc/manual/source/dynare-misc-commands.rst      |  6 ++++++
 matlab/utilities/general/clean_current_folder.m | 16 ++++++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/doc/manual/source/dynare-misc-commands.rst b/doc/manual/source/dynare-misc-commands.rst
index c7abd2e7e1..3cee5859c1 100644
--- a/doc/manual/source/dynare-misc-commands.rst
+++ b/doc/manual/source/dynare-misc-commands.rst
@@ -22,6 +22,12 @@ Dynare misc commands
 
     Puts the IRFs stored in ``oo_.irfs`` into vectors with the same name into the base workspace.
 
+.. matcomm:: clean_current_folder ;
+
+    Cleans the current folder from all files generated by Dynare for the mod-files currently located in
+    the current folder. It will delete all class files (+folders), log-files, and folders generated by 
+    previous runs of these files. Note that this also applies the results subfolder. Proceed with caution.
+
 .. command:: prior_function(OPTIONS);
 
     Executes a user-defined function on parameter draws from the prior
diff --git a/matlab/utilities/general/clean_current_folder.m b/matlab/utilities/general/clean_current_folder.m
index f458d6a641..4ea10a4bf9 100644
--- a/matlab/utilities/general/clean_current_folder.m
+++ b/matlab/utilities/general/clean_current_folder.m
@@ -1,6 +1,6 @@
 function clean_current_folder()
 
-% Copyright © 2014-2017 Dynare Team
+% Copyright © 2014-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -22,20 +22,20 @@ a = dir('*.mod');
 
 for i = 1:length(a)
     [~,basename] = fileparts(a(i).name);
-    if exist([basename '.m'])
-        delete([basename '.m']);
-    end
-    if exist([basename '.log'])
+    if isfile([basename '.log'])
         delete([basename '.log']);
     end
-    if exist(basename,'dir')
+    if isfolder(basename)
         rmdir(basename,'s');
     end
-    if exist([basename '_steadystate.m'])
+    if isfolder(['+',basename])
+        [~,~]=rmdir(['+', basename],'s');
+    end
+    if isfile([basename '_steadystate.m'])
         movefile([basename '_steadystate.m'],['protect_' basename '_steadystate.m']);
     end
     delete([basename '_*'])
-    if exist(['protect_' basename '_steadystate.m'])
+    if isfile(['protect_' basename '_steadystate.m'])
         movefile(['protect_' basename '_steadystate.m'],[basename '_steadystate.m']);
     end
 end
-- 
GitLab