?
Solved

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

Posted on 2009-05-14
7
Medium Priority
?
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Assisted Solution

by:bluntTony
bluntTony earned 600 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 1400 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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