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

VBS script to delete files which are older than 30 days

Status
Not open for further replies.

rock786143

Programmer
Aug 12, 2009
20
IN
I'm new to VBS.
I would like to delete files which are older than 30 days including folders automatically.
my folders structure is given below:


c:\path\archive\daily\YYYY-MM-DD
c:\path\archive\weekly\YYYY-MM-DD

i want to search under c:\path\archive\daily
c:\path\archive\weekly and delete the folders which are older than 30 days.

I appreciate if you could help me how to write a VBS or a batch script.



 
tyr google "vbscript older than 30 days"

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Try this code to delete files from a folder:

Private Sub DeleteFiles(ByVal DirectoryPath As String)
Dim files As String() = IO.Directory.GetFiles(DirectoryPath & "folder") - which folder you want to delete
For Each CurrentFile As String In files
Dim FileInfoDate As Date = IO.File.GetLastWriteTime(CurrentFile)
If FileInfoDate < Now.AddDays(-30) Then
IO.File.Delete(CurrentFile)
End If
Next

End Sub
 
jessiejane, your code is far away from VBScript ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top