vbscript List files with modified date (more than 3 year old

Great for for getting all Windows related scripts.

vbscript List files with modified date (more than 3 year old

Postby Praveen » Thu Aug 06, 2009 3:48 pm

This script is useful to delete the files which are more than 3 year old (you can mention the days also)
It gives proper report with last modified date, file path and size of the file in tsv format, you can open this in excel format.

'************ Start of Code **********************
'**********Script by Praveen Kumar****************
'*************************************************

Option Explicit

Dim oFSO, oFolder, sDirectoryPath, sStartPath, oFSO1, sReportName, fReport, oFldr
Dim oFileCollection, oFile, sDir
Dim iDaysOld

sStartPath = "E:\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSO1 = CreateObject("Scripting.FileSystemObject")
sReportName = "C:\log.txt"
Set fReport = oFSo1.CreateTextFile(sReportName, True)
fReport.WriteLine "File Path" & vbTab & "File Size" & vbTab & "Last Modified Date"
ListFolders(sStartPath)
Sub ListFolders(sDirectoryPath)
On Error Resume Next
iDaysOld = 1095

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection


If oFile.DateLastModified < (Date() - iDaysOld) Then

fReport.write oFile & vbtab
fReport.write oFile.Size & vbtab
fReport.Write oFile.DateLastModified & vbnewline
End If

Next
For Each oFldr In oFolder.SubFolders
ListFolders oFldr.Path
Next
End Sub

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
User avatar
Praveen
Site Admin
 
Posts: 84
Joined: Sat Apr 25, 2009 2:21 pm

Return to Windows Scripting/WMI/VBScript

Who is online

Users browsing this forum: No registered users and 0 guests

cron