global-functions: introduce $RmFile

This commit is contained in:
Christian Hesse 2025-01-21 18:16:57 +01:00
parent 4bfb591fa0
commit 4542c2b19e

View file

@ -63,6 +63,7 @@
:global ProtocolStrip; :global ProtocolStrip;
:global RandomDelay; :global RandomDelay;
:global RequiredRouterOS; :global RequiredRouterOS;
:global RmFile;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global ScriptInstallUpdate; :global ScriptInstallUpdate;
:global ScriptLock; :global ScriptLock;
@ -1004,6 +1005,26 @@
:return true; :return true;
} }
# remove file
:set RmFile do={
:local FileName [ :tostr $1 ];
:global LogPrint;
:local File [ /file/find where name=$FileName type=file ];
:if ([ :len $File ] = 0) do={
:return true;
}
:do {
/file/remove $File;
} on-error={
$LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed.");
:return false;
}
:return true;
}
# check if script is run from terminal # check if script is run from terminal
:set ScriptFromTerminal do={ :set ScriptFromTerminal do={
:local Script [ :tostr $1 ]; :local Script [ :tostr $1 ];