Funny you should ask this as I was just looking at how to do this today.
Most operating systems offer a way to search for files given a certain filter, such as being older than a certain date, and then piping that list to another command, such as delete.
Here is a class method I wrote to do this on a Windows 2012 R2 server running Cache
ClassMethod PurgeFiles(Path As %String, OlderThan As %Integer)
set cmd="forfiles /P "_Path_" /D -"_Date_" /C ""cmd /c del @path"""
This method accepts a path and an integer indicating the number of days to keep files for. It then uses constructs a command line which uses the "forfiles" command passing the path and a calculated date. For each file it finds, it executes the command cmd /c del <path> which deletes the file.
There are probably more elegant ways to do this, cross platform compatible, but this is one solution that I had.