![]() ![]() (One of the vagaries of working with text files: you can read from a file or you can write to a file, but you can’t do both at the same time.) We then write the value of strNewContents to the file. When we’re done reading the file we close it, then immediately reopen it for writing. If it is, we discard it if it’s not, we add that line (along with any other non-blank lines) to a variable named strNewContents. As we read each line we check to see if the line is blank. Because we can’t directly edit a text file we have to do this instead: First, we read in the text file line-by-line. As you probably know, manipulating text files often involves coming up with work-arounds. Let’s talk about the basic idea before we get into the nitty-gritty details of how the script works. Set objFile = objFSO.OpenTextFile(“C:\Scripts\Test.txt”, ForWriting) StrNewContents = strNewContents & strLine & vbCrLf Set objFile = objFSO.OpenTextFile(“C:\Scripts\Test.txt”, ForReading) Set objFSO = CreateObject(“Scripting.FileSystemObject”) What you’d like is for the text file to look like this: Line 1Ĭan you do that using a script? Of course you can: Const ForReading = 1 ![]() We’re assuming that you have a text file that looks something like this: Line 1 Not bad for a dead technology that nobody uses, huh? What’s the moral to all this? It’s now 2006, and the first question being tackled in the Hey, Scripting Guy! column is one dealing with text files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |