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?
Cherukuri30Service 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
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...)

only if you have file extensions hidden :)
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
Cherukuri30Service 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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.