|
|
WSH - FSO (File System Object)Introduction - Using FSO methods to create text filesThe Key to using VBScripts to create and manipulate files is to learn the best methods to manipulate the FSO (File System Object). FSO Create File Topics
♦ VBScript to Create a Text FileHere is a VBScript to make a text file. Once you have created the file, use the WriteLine method to add text. Whilst this may seem a cumbersome way of manipulating files, the learning points will help you create scripts which can automate reading and writing to files, Active Directory or the registry. 'VBScript Learning PointsIn our script example, fso (FileSystemObject) creates an object which we can manipulate. I have chosen the CreateTextFile method here, but be aware that there are other methods like CreateFolder or DeleteFile. Once you have created the file as a TextStream object, then we can start doing some useful work. To get text into the file, I have selected two methods to append data to the file, WriteLine and Write. WriteLine adds a carriage return and so makes a complete line of text. Whereas write, just adds text but creates no end of line marker. Finally, good practice is to tidy up with a Close statement. Note: Trap for you in the above script. Change the path on line 7. Point it to a folder on your machine. Set NewsFile = fso.CreateTextFile("c:\ezine\bestpractice3.txt", True)
Guy
Recommends: WMI Monitor and It's Free!
|
||||
Custom Search
|
Guy Recommends: WMI Monitor for Powershell
|
|
Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved. Please report a broken link, or an error to: | |