Link to home
Start Free TrialLog in
Avatar of Atouray
Atouray

asked on

Batch script to run every x seconds

I need a windows batch script to delete files from a specific folder for every x seconds.
Any ideas how to achieve this?
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Atouray
Atouray

ASKER

How can I start the script to run automatically when the machine is started? Also how can I make it run in the background?
Avatar of Atouray

ASKER

Also how can set path other than the C drive?
There are a few ways.  You could create a scheduled task and set it to run At System Startup.  You could also set the script to run under the group policy node Computer Configuration\Windows Settings\Scripts\Startup.

Change the path to the desired drive and directory by editing the folder variable on line 4.
Avatar of Atouray

ASKER

Shift-3 something just come up. I know it's bit different but it's what is needed. I need to script to delete files older than 30 seconds only. The script should only delete files older than 30 seconds. Is there any way to do this?

Thanks.
Yes, that would be possible with vbscript.
Avatar of Atouray

ASKER

Can you please help me on that and I would prefer it with C# if possible? I need badly thus if can get it now would be grateful.

Thanks.
I don't code in C#.  As your question has different requirements I'd recommend closing this one and using the "Ask a related question" link to post to pertinent zones.
Avatar of Atouray

ASKER

Since you solved the question I asked before I will award you the points. I've already started the script and now it works. The only thing left is to make it a service and repeat the delete command every 5 seconds in C#.

Thanks.