Link to home
Start Free TrialLog in
Avatar of bentham1
bentham1Flag for United Kingdom of Great Britain and Northern Ireland

asked on

I need this script to check just the date on folders

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
Avatar of Bill Prew
Bill Prew

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
Avatar of bentham1

ASKER

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.
SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial