troubleshooting Question

Help with VBScript

Avatar of mrsam3
mrsam3 asked on
Windows OSVB Script
5 Comments1 Solution336 ViewsLast Modified:
I am new to vb scripting but have the below script that will find OST and PST files on a computer and write to a file text document if the file is over a certain size. I want it to delete the file if it does not find anything (size = 0).

I believe adding the following code after the record.close should do it but it is not working . I still have blank files and I don't know why.

 if fileName.size=0 then FSO.deletefile fileName.path,true

Full Script
on error resume next
' Write what we're scanning for
path = "c:\"

Set FSO = CreateObject("Scripting.FileSystemObject")

fileName = Replace(Replace("file-sizes_" & date() & "_" & time() & ".txt","/","-"),":","-")
Set record = FSO.CreateTextFile(fileName, True)

ScanDirectory FSO.GetFolder(path)

record.close


Sub ScanDirectory(oFolder)
        on error resume next
	' Scan the Files in this Directory
	ScanFiles oFolder
	' Essentially iterate in this function with any additional folder names found
	For each folder in oFolder.SubFolders
                ScanDirectory folder
	Next
End Sub

Sub Scanfiles(oFolder)
        on error resume next
	' Checks files in a folder and outputs any that haven't been modified in x days
        recordNumber = 0
        For each file in oFolder.Files
		If file.size > 5368709120 Then
                       recordNumber = recordNumber + 1
                       record.WriteLine(recordNumber & " , " & file.Path & " , " & file.Size & "Bytes")
		End If
	Next
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros