We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

I need this script to check just the date on folders

bentham1
bentham1 asked
on
Medium Priority
244 Views
Last Modified: 2012-08-13
Hi, The script below works, but it deletes everything of that age. What I want it to do is check the dates on the folders directly under the "Done" directory. Not files in those subfolders or subfolders of those folders.  (Ie: done\test but not done\test\test1)
And delete the whole subfolder recursively.
Current script:
****************************************************************
Option Explicit
Dim fpath, fcount,fsoc,logname ,myday,mymonth
Dim daystokeep
daystokeep=182
fpath="D:\departments\TPD\Private\Change\Done"


Const ForAppending = 8 'Scripting.IOMode
myday=Day(DATE)
if len(myday)=1 then myday= "0" & myday
mymonth=month(DATE)
if len(mymonth)=1 then mymonth= "0" & mymonth
logname="D:\Private\Change\Done\Deleted" & myday & myMonth & Right(Year(DATE),2) & ".log"

Set FSOC = CreateObject("Scripting.FileSystemObject")

writelog "*************************************"
writelog "Start Purge of: " & fpath & " " & now()
writelog "Deleting Files older than: " & daystokeep & " Day(s)" & VbCrLf

ShowSubfolders FSOC.GetFolder(fpath)

Sub ShowSubFolders(Folder)
Dim subfolder
on error resume next
    For Each Subfolder in Folder.SubFolders
        ShowSubFolders Subfolder
        delfiles subfolder
        if subfolder.SubFolders.count=0 AND subfolder.files.count=0 then
           writelog "Folder " & subfolder & " Deleted"
         fsoc.deletefolder(subfolder)
           DisplayErrorInfo
        end if      
    Next
End Sub
*******************************************************************************8
Thanks
Mike
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
I don't currently see any checking of the age of files or folders, it just seems to be removing empty folders.

Do you want to delete the files under the done folder that are a cetain age, or only look at the date of the first level of subfolders under the done folder, and when they are old (based on last updated date?) remove that folder and all children?

A little confusing based on your post of:

 (Ie: done\test but not done\test\test1)
And delete the whole subfolder recursively.

which sounds like you want to remove the entire done\test folder, but then you also say not the \done\test\test1 folder?

!bp

Author

Commented:
Hi,
Yes, I would like to check the age of of the top level folders directly under the done folder and then delete the any of those folders and their children if the top level folder is older than 182 days.

Sorry I meant check the age of Done\test not \done\test\test1. But delete test and everything under it if  test is over 182 days.
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.