Hello:
I am trying to understand the meaning of a certain line of code for a
script that queries the event log and then writes it to a text file. I
found the script on the web. I would appreciate if someone could
explain the function of the following command in this script:
set objFile = nothing
set objFolder = nothing
What does the above do and what's it for? The relevant parts of the
script deailing with the file system object is listed below. THank you.
TIA
- Raheem
PS. The script below is from this excellent site on scripting
http://www.computerperformance.co.uk
----> Begin Script
Option Explicit
Dim objFSO, objFolder, objFile ' Objects
Dim strComputer, strFileName, strFolder, strPath ' strings
' --------------------------------------------------------
' Set the folder and file name
strComputer = "."
strFileName = "\Event672.txt"
strFolder = "e:\logs"
strPath = strFolder & strFileName
' -----------------------------------------------------
' Section to create folder and hold file.
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strFolder folder exists
If objFSO.FolderExists(strFolder) Then
Set objFolder = objFSO.GetFolder(strFolder)
Else
Set objFolder = objFSO.CreateFolder(strFolder)
WScript.Echo "Just created " & strFolder
End If
If objFSO.FileExists(strFolder & strFileName) Then
Set objFolder = objFSO.GetFolder(strFolder)
Else
Set objFile = objFSO.CreateTextFile(strFolder & strFileName)
Wscript.Echo "Just created " & strFolder & strFileName
End If
' --------------------------------------------------
' Two tiny but vital commands (Try script without)
set objFile = nothing
set objFolder = nothing
' ----------------------------------------------------
' Write the information to the file
Set strFileName = objFSO.CreateTextFile(strPath, True)
strFileName.WriteLine("Computer to test " & strComputer)
Wscript.Echo "Check " & strPath
WScript.Quit
' End of Guy's FSO sample VBScript
<---- End Script