Wells-it.com - Web Hosting

using crontab to empty a directory each morning

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 21 posts

Joined: Sep 2000

I've never used crontab before and I'm wondering if someone could explain to me how I can set it up to remove all files in a specific directory every morning at 2am.

Thank you.

They have: 21 posts

Joined: Sep 2000

Nevermind, I think I did it. I wrote a little script that wipes all the files in the directory except for itself and I set up a cron job to execute the file each morning. I know the script works but I guess I'll have to see if the cron job worked tomorrow morning.

It's always fun to learn new stuff.

Mark Hensler's picture

He has: 4,044 posts

Joined: Aug 2000

No wait... let me guess. You used PHP.
Wink

mairving's picture
Moderator

They have: 2,256 posts

Joined: Feb 2001

Quote: No wait... let me guess. You used PHP.

Even Easier to do would be a simple script like this

In Linux:
/path to directory/rm * , save it with the .sh extension and chmod it to make it executable.

In Windows:
cd /path to directory
del *
save as a .bat file.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Mark Hensler's picture

He has: 4,044 posts

Joined: Aug 2000

hmm... I never even thought about that.

.... .bat ... that brings back memories.. hehe