Solved

Folder cleanup script

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

911 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

22 Experts available now in Live!

Get 1:1 Help Now