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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to timestamp and delete files 1

Status
Not open for further replies.

tylerdurden68

IS-IT--Management
Jan 23, 2003
48
US
I have a common network share (Win2k server) that users are starting to fill up. It was intended as a temporary storage location, so I wanted to have a method to delete files after they had been on the share for 90 days. Is there a simple way to do this with a script? Basically so when someone puts a file on the share it will delete that file 90 days later, not all files in the share at once. I'm not a programmer, so any help is appreciated.
 
tylerdurden68,

Something like that:

Private Sub Command1_Click()
Dim objFSO As New FileSystemObject
Dim objFile As File
Dim objFolder As Folder

Set objFolder = objFSO.GetFolder("Your Share Directory")

For Each objFile In objFolder.Files
MsgBox objFile.Name & " " & objFile.DateCreated

If DateDiff("d", objFile.DateCreated, Date) > 90 Then
objFile.Delete True
End If

Next objFile

Set objFSO = Nothing
Set objFile = Nothing
Set objFolder = Nothing

End Sub

Set a reference to Microsoft Scripting Runtime in your VB project first.

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top