?
Solved

Folder cleanup script

Posted on 2009-04-07
2
Medium Priority
?
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 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