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!

Need to delete folder over 2 days old and starts with F 1

Status
Not open for further replies.

aclepore

MIS
May 15, 2008
4
US
Thanks in advance for the help. I have a script that will delete folders over 2 days old. I just don't know how to tweak it to only delete folders over 2 days which start with the letter "f".

Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSys.GetFolder("d:\test")
For Each Folder In objFolder.SubFolders
FolderCreated = Folder.DateCreated
FolderAge = DateDiff("d", FolderCreated, Now)
If FolderAge > 2 Then
Folder.Delete
End If
Next


Please help this noob out.
Thanks.
 
Google on FileSystemObject Folder Name would have retrieved....


Which would have told you that the folder name property is.....and this may seem bizarre.....called Name.

Hence

Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSys.GetFolder("d:\test")

For Each Folder In objFolder.SubFolders
FolderCreated = Folder.DateCreated
FolderAge = DateDiff("d", FolderCreated, Now)

If FolderAge > 2 And Left(Folder.Name,1) = "F" Then
Folder.Delete
End If
Next

C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top