Solved

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

Posted on 2009-05-14
7
278 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 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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

689 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