r/vbscript • u/666moneyman999 • Jun 28 '22
How do you read from a text file without reading in the header and footer
I have a script that does a number of operations on information from a text file, however the text file is required to have a header and a footer, so the first and last line are somewhat messing up the operations. Is there a way to not read the header and footer of a text file?
1
Upvotes
1
u/jcunews1 Jun 28 '22
In VBScript, and without additional help of a third party ActiveX, it's not possible. Mainly because in order to know which part of the file is the footer data, the script has to know the number of lines in a file - which can only be done by reading and counting them.
While VBScript has a
SkipLine()function, it still need to read the data from the file - in order to know the location of the next line. i.e. it needs to count the length of the current line first - by reading the file data, but doesn't need to return the retrieved data.So, is there a way to not actually read the footer? No, there is not. But, there a way to not need a variable for the footer data.
1
u/hackoofr Jun 28 '22
Can you post your vbscript code and the text example to read from ?
1
u/JGN1722 Jun 28 '22
you could put a character in the text file which you script would use to know where to start to read and when to end the reading
1
u/raging_radish Jun 28 '22
Look for the first and last CRLF?
https://www.google.com/search?q=look+for+the+first+and+last+crlf+vbscript
Or, if the header/footer text is constant you could filter it out.
1
u/hackoofr Jun 29 '22
Here is an example to read hosts file located on this path
"C:\windows\system32\drivers\etc\hosts"