Dear,Welcome to the board.
We are using in our version the GetFileTime function to get
the date of last modification of a file.
The change all "*.LOG" files to the format "YYYYMMDD.LOG". No renaming
when file is in use or new file already exist.
Our version:
code:
$log_directory="j:\drs1\drs1backup"
;
$tmp_file="%temp%\zzzzz.tmp"
SHELL '%comspec% /c dir "$log_directory\*.log" /b >$tmp_file '
IF (Open(1,$tmp_file,2) = 0)
$old_file=ReadLine(1)
WHILE (@error = 0)
? $old_file+" -> "+GetFileTime($old_file)
$fdate=GetFileTime($old_file)
IF (len($fdate) <> 0)
$new_file= substr($fdate,1,4)+substr($fdate,6,2)+substr($fdate,9,2)
; $new_file=$new_file+"_"+substr($fdate,12,2)+substr($fdate,15,2)+substr($fdate,18,2)
$new_file=$new_file+".log"
;
IF ($old_file <> $new_file) AND (Exist($log_directory+"\"+$new_file) = 0)
? 'rename "$log_directory\$old_file" "$new_file" '
shell '%comspec% /c ren "$log_directory\$old_file" "$new_file" '
ELSE
? '-skip- "$log_directory\$old_file" (duplicate entry)'
ENDIF
ELSE
? '-skip- "$log_directory\$old_file" '
ENDIF
$old_file=ReadLine(1)
LOOP
IF Close(1)
ENDIF
ENDIF
DEL $tmp_file
It is also possible to change it to "YYYYMMDD_HHMMSS.LOG" format. You only need
to remove ; symbol in line 12.
greetings.