Re: Make Mathematica wait for File
- To: mathgroup at smc.vnet.net
- Subject: [mg43822] Re: Make Mathematica wait for File
- From: Bill Rowe <browe51 at earthlink.net>
- Date: Tue, 7 Oct 2003 02:41:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 10/6/03 at 2:07 AM, yat at omrf.ouhsc.edu (YAT) wrote: > 1. How do I make Mathemtica wait from reading a file until the file > reaches a certain size? If[FileByteCount["file"]>x, ReadList["file",... > 2. How do I make Mathematica just go in and read a file, look for an > occurance of some text, then store that as my Mathematica variable, > rather than having to store the file as a Mathematica list, look for a > match then grab the value. It is a little unclear to me what you want to do here. When you say "look for an occurance of some text", is the text known beforehand? If so, FindList["file", "text", 1] will return the first line in the file containing the text. OTOH, if your goal is to look for the first occurance of a block of arbitrary text the task is much more complex. One approach would be to read the file byte by byte using Read[file, Byte] until the byte value returned is a text byte. This could be set up using a While loop. Once the first byte is found a second While loop could be used to read the file byte by byte until the byte read is not a text byte. Read bytes could be saved as a nested list (faster than saving as a flat list using Append) and the result changed to a string using, FromCharacterCode[Most[Flatten@list]] where list is the nested list of characters. The resulting string can be converted to a variable using ToExpression assuming the string of text characters consitutes a valid variable name.