bentham1
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\Ch ange\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\Dele ted" & myday & myMonth & Right(Year(DATE),2) & ".log"
Set FSOC = CreateObject("Scripting.Fi leSystemOb ject")
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(subfolde r)
DisplayErrorInfo
end if
Next
End Sub
************************** ********** ********** ********** ********** ********** ***8
Thanks
Mike
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\
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
Set FSOC = CreateObject("Scripting.Fi
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
writelog "Folder " & subfolder & " Deleted"
fsoc.deletefolder(subfolde
DisplayErrorInfo
end if
Next
End Sub
**************************
Thanks
Mike
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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