Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to delete $ntunin* folders older than 1 year

Status
Not open for further replies.

dukekern

MIS
Jan 16, 2003
6
US
I have got this code from elsewhere and seems to work when I tested it. But I need it to delete not only all folders and subfolders that have a date modified date older than 1 year but ONLY folders who's parent directory is $ntuninstall*. Can anyone help?

Option Explicit
Const intDaysOld = 365
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\test")
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
WScript.Echo objSubFolder.DateLastModified
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
WScript.Echo objSubFolder.DateLastModified
objSubFolder.Delete True
End If
Next
 
[1] Well, with that "code from elsewhere" that you're happy with, it starts with a folder (C:\test or something else) and deletes its subfolders per datelastmodified criterion. You don't delete the starting folder. With that kind of basic functionality, I can only deduce that, to suit your need, you just control the folder's name (c:\test or something, as given).
[tt]
dim sfolder, starget_prefix
sfolder="c:\test"
starget_prefix="$ntuninstall"
if strcomp(starget_prefix, left(sfolder,len(starget_prefix)),1)=0 then
'you existing script isolated the starting folder name
else
'do nothing
end if
[/tt]
[2] But with different "code" from somewhere else, where the starting point is different, you need to do different thing. Basically, you control the parent folder by objFolder.parentfolder (if it is not nothing) and check its name. If it is really the ancestor which matters, you loop upword the folder chain. That would be a whole different game.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top