Solved

Run command every day at 12am to delete files in folder

Posted on 2009-05-14
7
258 Views
Last Modified: 2012-05-07
Hi

I need to delete files contained in folder C:\afolder\ at 12am each day automatically.  

The OS is Windows 2003. How do I set this up (presumably a DOS command)

Thanks in advance for step-by-step  info
0
Comment
Question by:rwallacej
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Assisted Solution

by:bluntTony
bluntTony earned 150 total points
ID: 24387310
Save the below two commands as a batch file (.bat) and schedule a task to run the batch file at 12 every day.

The batch file is actually deleting the whole folder and re-creating it, which is the simple way. You can schdule the task using the 'at' command:

at 12:00 /every:monday,tuesday,wednesday,thursday,friday,saturday,sunday "c:\clearfolder.bat"

...where c:\clearfolder.bat" is the path/name of your batch file.



rd c:\afolder /S /Q
mkdir c:\afolder

Open in new window

0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 350 total points
ID: 24387338
Run this command:

schtasks /create /RU "NT AUTHORITY\SYSTEM" /SC DAILY /TN "Delete Files" /TR "%comspec% /c del C:\afolder /F /Q" /ST 12:00:00

Open in new window

0
 

Author Closing Comment

by:rwallacej
ID: 31581563
thank-you both kindly, I used option 2 but have awarded both points for help - I hope this is acceptable.

regards,

rwallacej
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 27

Expert Comment

by:bluntTony
ID: 24393066
Unless I'm missing something, the second solution only deletes the whole folder? You wanted to clear it and have it ready to use again.

That's why I used a batch to recreate it.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24394743
No, the DEL command only deletes files, not folders.  

From del /?:

If a directory is specified, all files within the directory
will be deleted.
0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24394763
Apologies - I thought I might have been missing something :)
0
 

Author Comment

by:rwallacej
ID: 24396346
hi bluntTony,
sorry I missed that! I don't want the whole folder deleted so your batch is what's needed. How do I setup the batch to run?
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question