Solved

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

Posted on 2009-05-14
7
242 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now