[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-21
Medium Priority
Last Modified: 2010-04-18
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.

Question by:andreni78
  • 4
  • 2
LVL 48

Assisted Solution

Jay_Jay70 earned 800 total points
ID: 16513652
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...)


Accepted Solution

Cherukuri30 earned 1200 total points
ID: 16513955
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
LVL 48

Expert Comment

ID: 16513970
only if you have file extensions hidden :)
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Expert Comment

ID: 16517216
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

Expert Comment

ID: 16517736
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 ?
LVL 48

Expert Comment

ID: 16518698
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!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.   …
This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

829 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