Using VBScript and the FileSystemObject to Replace Batch Files
Code Example
Back to Article
VBScript Source File
NAME: ExampleOne.vbs
AUTHOR: Matt Childs
DATE : 1/9/2001
COMMENT: Code to show example of using VBScript and FileSystemObject to
write utility files that could replace batch files.
Dim objFSO
Dim ofolder
Dim objStream
Set objFSO = CreateObject("scripting.filesystemobject")
'create the output file
Set objStream = objFSO.createtextfile("c:\search.log", True)
CheckFolder (objFSO.getfolder("c:\")), objStream
MsgBox "File Search Completed." + vbCr + "Please check c:\search.log for
details."
Sub CheckFolder(objCurrentFolder, objLogFile)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
strSearch = ".bat"
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
'Got one
strOutput = CStr(objFile.Name) + "," _
+ CStr(objFile.Path) _
+ "," + CStr(objFile.Size) _
+ "," + CStr(objFile.Type) + "," _
+ CStr(objFile.datelastaccessed)
objLogFile.writeline strOutput
End If
Next
'Recurse through all of the folders
For Each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objLogFile
Next
End Sub
Back to Article