Fileread / Filewrite alternate

Started by juergenk, July 15, 2015, 02:42:11 AM

Previous topic - Next topic

juergenk

Hello,

i will read an write textfiles with more then 26000 characters in line. Normaly winbatch functions FILEREAD has not enough. How can i do th read so long lines in Files ?

thanks for helping
juergen ;)

stanl


juergenk

With the Intcontrol 65 i have the same Error : 1591 line to long

Error 1591 FileRead: Zeile zu lang


td

FileRead's default behavior is to set the maximum line size to the lesser of the file size or 32767 bytes (not characters but bytes.) Based on this it is likely that one or more of the following is true:

  • You are using an old version of WinBatch.
  • You are not using IntControl 65 before you call FileOpen.
  • Your file lines are more then 32767 bytes long.
  • Your WinBatch process is very low on memory because of some other activity in the script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

Quote from: td on July 16, 2015, 07:41:41 AM
FileRead's default behavior is to set the maximum line size to the lesser of the file size or 32767 bytes (not characters but bytes.) Based on this it is likely that one or more of the following is true:

  • You are using an old version of WinBatch.
  • You are not using IntControl 65 before you call FileOpen.
  • Your file lines are more then 32767 bytes long.
  • Your WinBatch process is very low on memory because of some other activity in the script.
Two comments:
1) Isn't FileRead's default behavior to set the max line length to 4096 but that this can be increased with IC(65)?
Or has this changed recently (i.e., in the last 9 years) ?
2) Isn't the real answer to this (if one wants to really do it in full generality) to use BinaryRead() and friends?

td

Quote
Two comments:
1) Isn't FileRead's default behavior to set the max line length to 4096 but that this can be increased with IC(65)?
Or has this changed recently (i.e., in the last 9 years) ?

Don't recall exactly when it change but it now works as describe in my previous post.

Quote
2) Isn't the real answer to this (if one wants to really do it in full generality) to use BinaryRead() and friends?

No, if by 'real' you mean the only way to read files with long records.  The advantage of FileRead is that you can easily step through file 'records' one at a time when that is the intent.  However, if the file is not organized as delimited records the there is no advantage to FileRead.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

Right - I'm as a big a fan of FileRead() are you'll find, but I was thinking that if you need to read arbitrarily long records, then the Binary functions might be best.

I.e., if you can't answer the question "What is the longest line I might encounter?"

td

Well, given the previous stated caveats, you can simply set the record size to the size of the file and have the benefits of BinaryRead while still using FileRead with its benefits.  Of course, if the file is of very large size then you would  need to use BinaryReadEx along with the Huge Math extender.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

If I remember, WB's fileread still has a max length but is greater than the 26000 the OP listed.

Needless to say, OP needs to provide test data.

td

As previously mentioned the default maximum line length is  the lesser of  32767 bytes or the size of the file ( if the file size is less than 4096 byte, 4096 is used.) Using IntControl 65 you can set the line length to anything up to MAX INT, if you choice. But because of memory limitations, the actual record size limit is probably somewhere around 100 to 250 MB.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade