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.

C:\Logs\Folder1\*.gz
C:\Logs\Folder2\*.gz
C:\Logs\Folder3\*.gz
andreni78Asked:
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
0
 
Jay_Jay70Commented:
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")
   fso.DeleteFile("c:\Logs\Folder1\*.gz")

   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile("c:\Logs\Folder2\*.gz")

   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile("c:\Logs\Folder3\*.gz")
_________________________

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

Cheers!
0
 
Jay_Jay70Commented:
only if you have file extensions hidden :)
0
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.

 
Jay_Jay70Commented:
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
0
 
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 ?
0
 
Jay_Jay70Commented:
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!
0
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.