Scripts to automatically delete specified files on specified folders with a schedule ***500 points

Hello Experts,

I have logs file that I would like to delete daily using windows scheduler. Can some one write me a complete solution using window batch or script ? and show me how to setup a schedule to run every night STEP BY STEP?  Thank you very much.

I would like to be able to specify folder and file wild card like below, and I can remove any entry and add new entries.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi andreni78,

here is some code that you place directly into a notepad file and save as whatever.vbs. This will delete anything with a .gz extensions

You can of course modify this to do whatever folders you like
Dim fso
' Delete all .gz files within folder c:\Logs\Folder1 and c:\Logs\Folder2 and c:\Logs\Folder3

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set fso = CreateObject("Scripting.FileSystemObject")

to add this as a schedulaed task you need to go to start - programs - Accesories - system tools - Scheduled Tasks

run through the wizard and add your whatever.vbs file as the task to run, add the time you want it to run and you may want to run it is as the administrator (part of the wizard...)

Sridhar CherukuriService EngineerCommented:
In addition to Jay Jay70 solution you can also do this with .bat file

@echo off
del C:\Logs\Folder1\*.gz
del C:\Logs\Folder2\*.gz
del C:\Logs\Folder3\*.gz

copy the above 4 lines in notepad and save it as <file name>.bat

whether it is .VBS or .BAT file when you are saving it through notepad make sure "Save as Type" changed to All Fles otherwise it will be saved as

filename.VBS.txt or filename.BAT.txt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
only if you have file extensions hidden :)
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

did the second answer given work? i tried it but it would never delete all the files and alwyas wanted confirmation

what was i missing
Sridhar CherukuriService EngineerCommented:
Hi JayJay70, It works but since you mentioned it is asking for conformation i just tried again, it is deleteing all the files with out asking for any confirmation.

May i know how you did it ?
ahh what i was doing wrong was putting in *.* and trialling - it wouldnt delete certain files but not briefcase for example

i tried that option first the wronte a vbscript - first one ever lol!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.