Reading from a specific line
Written by: webDOMinator 2 years and 6 months ago
Recently in version 2.5.3 of webDOM the read command has been updated to include a way to read from just one line of a file instead of having to read through multiple lines to get to just the one you want. This looks like
Code
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings.:thirdline=
openQuick Reference for "open"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: open:access-mode:file-handle;filename
Description: Opens the filename file for read, write, or append access, specified by access-mode, and makes it accessable through file-handle. Access modes can be (r,w,a,r+,w+, or a+). If a "+" is signified for extended access, this leaves the file open beyond the run-time of the script until it is closed by the user. Extended access files are helpful for instances where the file is a list of items, and each time the script runs, the next item needs to be read and used.:r:foo;c:\blah.txt
readQuick Reference for "read"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: read:file-handle:variable
Description: Reads the next line from the file specified by file-handle into variable. The variable can be any var, global, or a DOM or program variable.:foo#3:var.thirdline
closeQuick Reference for "close"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: close:file-handle
Description: Closes the file specified by file-handle.:foo
echoQuick Reference for "echo"
Click on command to see examples & comments
Script Level Commands
Usage: echo:statement
Description: Echoes a statement to the status output. The statement can be a literal string, or a concatenated string.:var.thirdline
The above code will just pull out the third line of the file "blah.txt" and echo it to the status & output window.
So the use of the #3 pulls out the third line of the file handle associated with it. In this case from the file handle "foo".
NOTE: If you do not close a file, it will not reset where webDOM reads from the file when using the single line read method. This means that if you forget to close the file and you want to do another specific line read of the file it will pull the incorrect information. This can also be considered that instead of pulling from the mentioned line, it's pulling from the last line + whatever number you mentioned... ie:
Code
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings.:thirdline=
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings.:fourthline=
openQuick Reference for "open"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: open:access-mode:file-handle;filename
Description: Opens the filename file for read, write, or append access, specified by access-mode, and makes it accessable through file-handle. Access modes can be (r,w,a,r+,w+, or a+). If a "+" is signified for extended access, this leaves the file open beyond the run-time of the script until it is closed by the user. Extended access files are helpful for instances where the file is a list of items, and each time the script runs, the next item needs to be read and used.:r:foo;c:\blah.txt
readQuick Reference for "read"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: read:file-handle:variable
Description: Reads the next line from the file specified by file-handle into variable. The variable can be any var, global, or a DOM or program variable.:foo#3:var.thirdline
echoQuick Reference for "echo"
Click on command to see examples & comments
Script Level Commands
Usage: echo:statement
Description: Echoes a statement to the status output. The statement can be a literal string, or a concatenated string.:var.thirdline
readQuick Reference for "read"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: read:file-handle:variable
Description: Reads the next line from the file specified by file-handle into variable. The variable can be any var, global, or a DOM or program variable.:foo#2:var.secondline
echoQuick Reference for "echo"
Click on command to see examples & comments
Script Level Commands
Usage: echo:statement
Description: Echoes a statement to the status output. The statement can be a literal string, or a concatenated string.:var.secondline
closeQuick Reference for "close"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: close:file-handle
Description: Closes the file specified by file-handle.:foo
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings..secondline would not actually be the second line, since the file line cursor was already at 3, it would be 3 + 2 thus var.secondline would contain whatever was in the fifth line. In this case, it's best to do something like:
Code
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings.:secondline=
varQuick Reference for "var"
Click on command to see examples & comments
Variable Setting Commands
Usage: var:variable-name = expression
Description: Sets the variable specified variable-name to expression. Expression can be any concatenated string, literal text, or Mathematical expression, and can include other variables, DOM elements, or webDOM settings.:thirdline=
openQuick Reference for "open"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: open:access-mode:file-handle;filename
Description: Opens the filename file for read, write, or append access, specified by access-mode, and makes it accessable through file-handle. Access modes can be (r,w,a,r+,w+, or a+). If a "+" is signified for extended access, this leaves the file open beyond the run-time of the script until it is closed by the user. Extended access files are helpful for instances where the file is a list of items, and each time the script runs, the next item needs to be read and used.:r:foo;c:\blah.txt
readQuick Reference for "read"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: read:file-handle:variable
Description: Reads the next line from the file specified by file-handle into variable. The variable can be any var, global, or a DOM or program variable.:foo#2:var.secondline
readQuick Reference for "read"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: read:file-handle:variable
Description: Reads the next line from the file specified by file-handle into variable. The variable can be any var, global, or a DOM or program variable.:foo:var.thirdline
closeQuick Reference for "close"
Click on command to see examples & comments
Filesystem and Shell Commands
Usage: close:file-handle
Description: Closes the file specified by file-handle.:foo
echoQuick Reference for "echo"
Click on command to see examples & comments
Script Level Commands
Usage: echo:statement
Description: Echoes a statement to the status output. The statement can be a literal string, or a concatenated string.:var.secondline
echoQuick Reference for "echo"
Click on command to see examples & comments
Script Level Commands
Usage: echo:statement
Description: Echoes a statement to the status output. The statement can be a literal string, or a concatenated string.:var.thirdline
The third line in this case comes right after the second line so we used just a regular read command with no line number included.