My hoster offers PHP as scripting language and I want to setup a CRON. The CRON is basically a GUI where I can enter the script path and script language (PHP). I need a small script which runs recursively over all folders and files, checking the age and deleting all files older than eg 14days. The PHP needs to be standalone, so that I can be copied to the .php file. PHP version is up to 5.4.
I'm not a big fan spoon-feeding whole scripts, but here are some pointers.
You can get a list of all files and folders in a path using an RecursiveDirectoryIterator
, passing this to an RecursiveIteratorIterator
can make the tree structure flat so you can loop trough it. For a small script I'd probably just filter inside that loop, if you think you might need more flexibility (for example pluggable strategies) later on you should check out FilterIterator
and RecursiveCallbackFilterIterator
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.