script to delete files.

Hello,

I would like to develop a script that enables the deletion of my log files.
However, I would like them to be deleted only if they are older than one year compared to the mikrotik’s date.
Below, I present the script I have attempted to create, but unfortunately, it does not produce the expected results.
Do you have suggestions ?

:global time [/system clock get time]
:global logskeep 31536000000
:foreach file in=[/file find] do={
:global filename [/file get $file name]
:global filetime [/file get $file creation-time]
:global timedifference ($time - $file_time)

:if ($time_difference > $logskeep) do={
/file remove $file_name
}
}

Shows you your problems:

{
:local t [/system clock get time]
:put "time: $t"
:local logskeep 31536000000
:foreach f in=[/file find] do={
 :local fileTime [/file get $f creation-time]
 :put "filetime: $fileTime"
 :if (($t - $fileTime) > $logskeep) do={
  #/file remove $f
 }
}
}

Shows time items:

/system clock print
                  time: 19:16:16
                  date: 2023-08-18
  time-zone-autodetect: no
        time-zone-name: Europe/Amsterdam
            gmt-offset: +02:00
            dst-active: yes

Then:

/system/clock> :put  ([/system clock get date]." ".[/system clock get time])
2023-08-18 19:22:11
/system/clock> :put [:typeof ([/system clock get date]." ".[/system clock get time])]      
str

In v7.12 Beta is an convert to Epoch which enables you to just subtract the time from time.