Previous Page
Next Page

Creating Files

There are literally thousands of times when a network administrator needs to create a file. The most common occurrence is when output needs to be captured from a command prompt or from the running of a script. By the time you finish this chapter, you'll have a section of code that you can reuse again and again. Once you know how to create files, you can use this code section instead of the WScript.Echo command to direct output to either the command prompt or a dialog box. (Later on, in Chapter 14, "Configuring Networking Components," you'll learn how to automatically invoke Notepad.exe to facilitate reading of the output.) What is involved in creating a file? The following "Just the Steps" section explains the process at a high level.

Just the Steps

To create a file

1.
Use CreateObject to create an instance of FileSystemObject.

2.
Use the CreateTextFile method.

3.
Include the full path and the name of the desired file.


As you can see from the preceding steps, the creation of a text file via VBScript is a very easy and straightforward process. In fact, it can be accomplished with just two lines of code, as seen in the listing for CreateTextFile.vbs.

CreateTextFile.vbs

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateTextFile("C:\FSO.txt")


Previous Page
Next Page