Hello,
I am new to VBScript. Ultimately I am trying to create a script that will check the recyclebin (c:\recycler) and then delete all files in subfolders that are more than 30 days old.
I can successfully delete files in the c:\recycler folder that are more than 30 days old. I can also list the subdirectories in the c:\recycler folder. But I can't figure out how to integrate the 2 into a script that will delete files that are in those subfolders. I have provided the 2 seperate pieces of code below. Any help integrating these would be greatly appreciated.
Path1 = "C:\RECYCLER"
Dim fso
Dim oFolder
Dim oFile
Dim oSubFolder
Set fso = createobject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path1)
For Each oFile In oFolder.files
If DateDiff("d", oFile.DateCreated,Now) > 10 Then
oFile.Delete True
End If
Next
Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing
**************************************************
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Recycler")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
ShowSubFolders Subfolder
Next
End Sub
I am new to VBScript. Ultimately I am trying to create a script that will check the recyclebin (c:\recycler) and then delete all files in subfolders that are more than 30 days old.
I can successfully delete files in the c:\recycler folder that are more than 30 days old. I can also list the subdirectories in the c:\recycler folder. But I can't figure out how to integrate the 2 into a script that will delete files that are in those subfolders. I have provided the 2 seperate pieces of code below. Any help integrating these would be greatly appreciated.
Path1 = "C:\RECYCLER"
Dim fso
Dim oFolder
Dim oFile
Dim oSubFolder
Set fso = createobject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path1)
For Each oFile In oFolder.files
If DateDiff("d", oFile.DateCreated,Now) > 10 Then
oFile.Delete True
End If
Next
Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing
**************************************************
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Recycler")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
ShowSubFolders Subfolder
Next
End Sub