Solved

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

Posted on 2009-05-14
7
250 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I have never ceased to be amazed how many problems you can encounter on a fresh install of a Windows operating system.  This is certainly case in point& Unable to complete ANY MSI installation.  This means Windows Updates are failing and I can't …
Learn about cloud computing and its benefits for small business owners.
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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