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!

I would like to create a vb script that does the following...

Status
Not open for further replies.

omxcunn

Programmer
Sep 2, 2009
4
US
Path =M:\
Delete *.bak,*.ndx and *.idx files that are 90 days or older
Move the files and folders not deleted to \\CLI-Arch

Path= M:\Job Que
Data in this directory that is 90days or older will be deleted.

Path = P:\Laser Output
Data in this directory that is 90days or older will be deleted.

Path = P:\ektajet
Data in this directory that is 90days or older will be deleted.

Path = P:\iminfo
Data in this directory that is 90days or older will be deleted.

Path= N:\
Data in this directory that is 90days or older will be deleted.

Path= M:\Vault
This directory is excluded.

Thanks for your help
 
What have you tried so far?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
This is what I have so far...

Dim fso, startFolder, OlderThanDate

Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "C:\test\"
OlderThanDate = DateAdd("d", -90, Date) ' 90 days (adjust as necessary)

DeleteOldFiles startFolder, OlderThanDate

Function DeleteOldFiles(folderName, BeforeDate)
Dim folder, file, fileCollection, folderCollection, subFolder

Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection

If file.DateLastModified < BeforeDate Then
fso.DeleteFile(file.Path)
End If

Next

Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
DeleteOldFiles subFolder.Path, BeforeDate
Next
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top