MyBB Community Forums

Full Version: Script to Delete Files every 24 hours
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
What I want to do is simply have a script that will run every 24 hours and will delete files from the folder specified without actually deleting the folder. Help would be nice and I would love you forever. Also, I have another folder in the folder that I want the files to be deleted from that I don't want deleted.

Here is what I want in a image type of thing...

-Folder 1 *Don't Delete*
-File *Delete*
-File *Delete*
-File *Delete*
-File *Delete*
---Folder Inside of Folder 1 *Don't delete*
For a machine or folder, MyBB attachments etc? Server? What OS? Do you have root? If yes, do you log off every 24 hours?
Server, Linux, I think I have root, but I am able to run Cron Scripts.

Pic of what I can see,
[Image: screenshot20100414at8.jpg]
Crons are past me. Sorry Sad
Ok, I have a new request.

I want the script to delete .png files every 24 hours in a certain folder.
well the command would be "rm /location/of/folder/*.png". I'm pretty sure you can set up a cron just using that. However if you coudn't you could make a simple script with that in it and just run the script.
Wouldn't be really hard.
Read up on php.net/readdir
and them i think the command to delete a file in php is kill or rm or so.
You'll find it, really easy Smile
Set a cron for:

<?php
shell_exec("rm -rf /path/to/folder/*");
?>
If your using cPanel just set up a cron job with the following command to run every 24h:
php /home/yourusername/taskfilename.php

Where yourusername is your cPanel username and taskfilename is the name of your PHP file, put it in the highest directory of your account, above public_html
Thanks.
I set it to run every 6 hours. Hope it works.

Thanks again.
Pages: 1 2