Solved

Folder cleanup script

Posted on 2009-04-07
2
681 Views
Last Modified: 2012-05-06
Hi,

I have a script (below) the runs on a schedule to clean up old folders. We have an automated system that puts new builds of a software development in folders in E:\XXX\PCInstaller\

I want a script that deletes any folders older than 1 week to keep the area clean. I tried using the below but obviously (now) it only deletes FILES and not folders.

Anyone help me on modding it so it works as I wish?

Thanks
@echo off
 
Forfiles -p E:\XXXX\PCInstaller\ -m *.* -d -7 -c "cmd /c del /q @path"

Open in new window

0
Comment
Question by:bheroniphr
  • 2
2 Comments
 

Author Comment

by:bheroniphr
ID: 24140087
Upping the points as had no feedback
0
 

Accepted Solution

by:
bheroniphr earned 0 total points
ID: 24160335
Hi,

I found this elsewhere.

Line to specify folder to run within:
BasePath = ""

Line to select how many days back you wish to script to exclude:
if CalcResult > 2 then

Hope this helps someone!

Ben
Dim i, fso, f, f1, sf, BasePath, CalcResult, fNameArray()
BasePath = "D:\Reports"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(BasePath)
Set sf = f.SubFolders
For Each f1 in sf
     CalcResult = DateDiff("d",f1.DateCreated,Now)
          if CalcResult > 2 then
                ReDim preserve fNameArray(i)
                fNameArray(i) = f1.Name
                i = i + 1
        end if
Next
 
For Each fName in fNameArray
    FSO.DeleteFolder(BasePath & "\" & fName)
Next

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

776 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