Re: [PHP] Purging old files from directories
I need to write a script that will scan/read a given directory's contents and delete files older than a certain date. Ideally, this will be a script that runs via cron once a week and deletes all files it finds in the directory older than 2 weeks from the current date. I do currently have scripts running via cron and that's no problem. I'm not sure where to begin with the other components Don't bother with PHP for tasks like these - just use the standard unix find program. The following one-liner should work: find /path/to/your/dir -mtime +14 -type f -print0 | xargs -0 rm -f man find, man xargs for more info. -mike. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Purging old files from directories
Verdon vaillancourt wrote: Hi :) I need to write a script that will scan/read a given directory's contents and delete files older than a certain date. Ideally, this will be a script that runs via cron once a week and deletes all files it finds in the directory older than 2 weeks from the current date. I do currently have scripts running via cron and that's no problem. I'm not sure where to begin with the other components Begin in the manual: Directory functions Filesystem functions - filemtime() I'm not looking to be spoon-fed, but I was hoping that someone could point me in the right direction to start researching. Best regards, Verdon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Purging old files from directories
On Friday 01 August 2003 21:40, Verdon vaillancourt wrote: I need to write a script that will scan/read a given directory's contents and delete files older than a certain date. Ideally, this will be a script that runs via cron once a week and deletes all files it finds in the directory older than 2 weeks from the current date. I do currently have scripts running via cron and that's no problem. I'm not sure where to begin with the other components I'm not looking to be spoon-fed, but I was hoping that someone could point me in the right direction to start researching. Reading manual Directory functions manual Filesystem functions manual Date and Time functions should get you started. If possible, it's a lot easier and more efficient to use a shell script instead. A single find command will do the job. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Do it by the book -- Anti- Murphy's Laws n5 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Purging old files from directories
Thank you :) On 8/1/03 10:06 AM, Marek Kilimajer [EMAIL PROTECTED] wrote: Begin in the manual: Directory functions Filesystem functions - filemtime() -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Purging old files from directories
* Thus wrote Verdon vaillancourt ([EMAIL PROTECTED]): Hi :) I need to write a script that will scan/read a given directory's contents and delete files older than a certain date. Ideally, this will be a script that runs via cron once a week and deletes all files it finds in the directory older than 2 weeks from the current date. I do currently have scripts running via cron and that's no problem. I'm not sure where to begin with the other components hm.. there are tools aleady available that do this on unix. find /path/to/files/ -type f -mtime '+14' -exec rm {} \; I'm not looking to be spoon-fed, but I was hoping that someone could point me in the right direction to start researching. If you still desire to write a php script: php.net/dir - for directory reading stuff php.net/stat - gets the stats on files. HTH, Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php