Tris
6 years agoContributor
Delete a file based on date?
Hi all, I've been looking for a way to manage files by deleting based on the files creation date. I've seen the aqFile.GetCreationTime method, however this appears to want a specific file nam...
- 6 years ago
I would use a combination of several objects. You should use the aqFileSystem object and the method "findfiles" to retrieve a list of files. Then you can iterate through that list (all aqFileInfo objects) and, if the CreatedDate matches what you're looking for, delete it.
Relveant objects:https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobjiterator/index.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfileinfo/index.html
- 6 years ago
Good spot, I've refactoted it in to a single routine as below.
function LogManager() { var foundFiles, aFile; foundFiles = aqFileSystem.FindFiles("C:\\Automation\\Log\\All", "*"); if (foundFiles != null) while (foundFiles.HasNext()) { aFile = foundFiles.Next(); var DateTime = aqDateTime.Now(); var DateTimeMinusXDays = aqDateTime.AddDays(DateTime, -14); if (aFile.DateCreated < DateTimeMinusXDays) { aFile.Delete(); } } else Log.Message("No log files were found."); }