Solved

Folder cleanup script

Posted on 2009-04-07
2
679 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now