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 name.
Is there any way within test complete of finding files (more than one) based on their creation date in order to then use this information to delete them?
I have a feeling this might be something for a batch job to do, which will take a fraction of the time to do this way over the amount of time I've spent looking for a way to do this within TestComplete.
Many thanks.
Tris
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
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."); }