Navigating the Memory Buffer

It seams apparent that the Windows Scripting Host (WSH) does not contain sufficient properties or methods in connection with manipulating the contents of a text file. I have no problem opening a text file and reading line by line or the entire file into memory at once. From there I can execute replace functions with RegExp and Replace().

But how can I navigate the file pointer around to pluck individual elements from the bufferized file? I need to be able to do this in order to extract needed data and write it to a new file.

All my VBScript, WSH and ASP web and book resources happily point out that this is a breeze once the datastream has been fed into the memory buffer, but no information or direction is supplied on how to work with a bufferized file beyond the range of arsenal offered by WSH and VBScript. Have I missed something in VBScript, cause I am almost certain I haven't missed anything in WSH?

In summary, once the file is in memory, I need to be able to position the pointer at specific coordinates using either variable logic or coordinate numbers, and then read from there forward. Preferably, I would process line by line and need to have the ability to remove blank lines. Does such a command/function even existing within the scripting domain to do this?

Please point me in the right direction and/or provide examples. Allow me to express my thanks and gratitude in advance.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Ken,

search for:

  var ForReading = 1;
  fso = new ActiveXObject("Scripting.FileSystemObject")
  ts = fso.OpenTextFile(txtFile, ForReading)
  s = ts.ReadAll()

If there is a 'ReadAll' (& writeLine() ) method, there must be a ReadLine method


Sub ReadFiles
   Dim fso, f1, ts, s
   Const ForReading = 1
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
   ' Write a line.
   Response.Write "Writing file <br>"
   f1.WriteLine "Hello World"
   ' Read the contents of the file.
   Response.Write "Reading file <br>"
   Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
   s = ts.ReadLine
   Response.Write "File contents = '" & s & "'"
End Sub
function ReadFiles()
   var fso, f1, ts, s;
   var ForReading = 1;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f1 = fso.CreateTextFile("c:\\testfile.txt", true);
   // Write a line.
   Response.Write("Writing file <br>");
   f1.WriteLine("Hello World");
   // Read the contents of the file.
   Response.Write("Reading file <br>");
   ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
   s = ts.ReadLine();
   Response.Write("File contents = '" + s + "'");
mficorpAuthor Commented:
Thank you for the feedback, but this reply did not even come close to answering my question. You can imagine with the detailed description of my problem that basic resources such as MSDN had already been explored. But I appreciate your effort and encourage you to reread my original posting and explore the depth of the question.

Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

mficorpAuthor Commented:

Again, thanks. But the problem I am having is not reading the file into memory (iow a variable), rather, manipulating the file in expert fashion once inside the memory buffer. Moving around the memory buffer.... using whatever logic or coordinate function/system that may be available.


I did read your post the first time, you are asking how to access lines within a buffer I had assumed the code I posted had a 'skipLine' method within it; that's what I get for assuming.

from the page posted above
If you use the Read or ReadLine method and want to skip to a particular portion of data, use the Skip or SkipLine method. The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string functions (such as Left, Right, and Mid), concatenated, and so forth.

if I am still wrong in what you are asking...

I am neither an asper nor a vber (javascript/c  ok)

but what you want to do is something like:
   do {
   s = ts.ReadLine();
   if (s.indexOf(someVar) != -1)    doSomething(s)
   else ts.SkipLine();
   } while (!ts.eof)

go to and search for SkipLine

Dim StdIn, StdOut, Str1, Str2

Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

Str1 = ""
Str2 = ""

For i = 0 to 4

i = 0
Do While Not StdIn.AtEndOfStream
     If i >= 2 Then
          StdOut.WriteLine Str1
     End If
     i = i + 1
     Str1 = Str2
     Str2 = StdIn.ReadLine

mficorpAuthor Commented:

I think now you understand my question. Am I correct in assuming that you are telling me there is no better way to move left or right across a line to hone in on a data segment other than using VB parse functions Left,Right,,Mid? Because that was my true question.. I needed a better way to parse, due to the limited and cumbersome nature of those very VB functions!

Your code sample was interesting, but I didn't recognize it as fully VBScript.

Hi Ken,

  If you mean the do while loop, it isn't vbscript -- it's pseudo-javascript.
I don't know vbscript, I only code.  Doesn't vb have an indexOf method?  some function that tells you if something is contained by something else?
If not, then I would suggest one of 2 things:

1) either call a javascript function from within your vb/asp
2) or, split each line on " " (space) into an array and loop through the array  in javascript it would be something like:

  line= fs.ReadLine();
  tmp = line.split(" ")
  for (i = 0; i < tmp.length; i++)
   if (tmp[i] == someValue)

mficorpAuthor Commented:

Your latest example had already been viewed by me. Unfortunately, the Stdx properties of the Skipline method are naccessible under the Wscript host.. CScript host only. But they are of limited value.

Hi Ken,
Sorry it's been awhile, but the real know...

Does this help any?

Set fso = CreateObject("Scripting.FileSystemObject")
Set tso = fso.OpenTextFile(filename,1,false,0)
response.write tso.ReadLine

google search results:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mficorpAuthor Commented:
Thanks Vinny, I consider the issued resolved. Apparently VBScript Objects, Properties and Methods fall short of the capability that I need. I appreciate your effort and you did provide the answer I was looking for, though I did seek additional info.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.