Advertisement

04.25.2008 at 09:27AM PDT, ID: 23354041
[x]
Attachment Details

Where can I find a VB script to delete all the files in a set of directories beyond a certain age?

Asked by amendala in Windows XP Operating System, Visual Basic Programming, Microsoft Windows Operating Systems

Tags: Microsoft, VB Script

Greetings -

I am looking for a script that will target a specific directory (and all subdirectories within it) and will delete any files it encounters that are beyond a certain age.  So I would be able to specify "30 days" since last modified and have it go delete all those files in my target path while recursing through subs.

I wrote this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\windows\temp")
For Each efile in objFolder.Files
 If DateDiff("d",eFile.DateLastModified,Now) >= 1 Then
   WScript.Echo "File found: " & efile
   objFSO.DeleteFile(eFile)
 End If
Next

However, that only takes into account the c:\windows\temp directory.  How can I modify this code to include all subdirectories?

If you're going to post a code snippet, please post the ENTIRE code sample with your changes, not just lines for me to "change".  That gets messy.

Thanks so much!Start Free Trial
[+][-]04.25.2008 at 09:39AM PDT, ID: 21441153

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 09:47AM PDT, ID: 21441215

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 10:01AM PDT, ID: 21441343

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows XP Operating System, Visual Basic Programming, Microsoft Windows Operating Systems
Tags: Microsoft, VB Script
Sign Up Now!
Solution Provided By: peetm
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.25.2008 at 10:47AM PDT, ID: 21441723

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 10:55AM PDT, ID: 21441812

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 11:09AM PDT, ID: 21441932

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 01:05PM PDT, ID: 21442821

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628