Q: Is there any option for a delete rule to keep a number of files, e.g. keep the last 10 Files, in the specific delete Folder I’m watching in?
We’re trying to handle our LOG Folder with Limagito. These LOG Files are not written permanently within a specific timeslot so it would be great to have this Log Rotation Option. Maybe there is a scriptsolution?
A: Yes this is indeed possible with Pascal Script (we tested this with version v2022.3.18.0).
1.Function is set to Delete
2.Source must be a Windows Folder or share
3. Set ‘Source File Sort Order’ to ‘File last write date ascending (Old to New)
4.Open Pascal Script setup:
5.Enable and add the following ‘On Destination’ Pascal Script (you can adjust the Const values of ctKeepFiles, ctSearchExt and ctSearchSubDirs):
Var tmpCount: Integer; Const ctKeepFiles = 10; ctSearchExt = '*.log'; ctSearchSubDirs = True; // True or False Begin // ... add your code here tmpCount := psCountFiles(psFilePath, ctSearchExt, ctSearchSubDirs); // Check If tmpCount > ctKeepFiles Then Begin psExitCode := 1; End Else Begin psLogWrite(1, '', 'Skip Delete, Minimum count reached'); psExitCode := -2; End; End.
You’ll find ‘Skip Delete’ in the RunTime Log when the minimum amout of log files needed is reached. Further deletes will be skipped.
If you need any info about this ‘keep a number of files’ request, please let us know.