global-functions: introduce $RmDir

This commit is contained in:
Christian Hesse 2025-01-21 18:21:28 +01:00
parent 4542c2b19e
commit 727495d9c4

View file

@ -63,6 +63,7 @@
:global ProtocolStrip; :global ProtocolStrip;
:global RandomDelay; :global RandomDelay;
:global RequiredRouterOS; :global RequiredRouterOS;
:global RmDir;
:global RmFile; :global RmFile;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global ScriptInstallUpdate; :global ScriptInstallUpdate;
@ -1005,6 +1006,26 @@
:return true; :return true;
} }
# remove directory
:set RmDir do={
:local DirName [ :tostr $1 ];
:global LogPrint;
:local Dir [ /file/find where name=$DirName type=directory ];
:if ([ :len $Dir ] = 0) do={
:return true;
}
:do {
/file/remove $Dir;
} on-error={
$LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed.");
:return false;
}
:return true;
}
# remove file # remove file
:set RmFile do={ :set RmFile do={
:local FileName [ :tostr $1 ]; :local FileName [ :tostr $1 ];