Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Folder cleanup script

Posted on 2009-04-07
2
Medium Priority
?
690 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

650 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