WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: juergenk on July 15, 2015, 02:42:11 AM

Title: Fileread / Filewrite alternate
Post by: juergenk on July 15, 2015, 02:42:11 AM
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 ;)
Title: Re: Fileread / Filewrite alternate
Post by: stanl on July 15, 2015, 04:45:04 AM
perhaps IntControl 65
Title: Re: Fileread / Filewrite alternate
Post by: juergenk on July 15, 2015, 11:27:24 PM
With the Intcontrol 65 i have the same Error : 1591 line to long

Error 1591 FileRead: Zeile zu lang

Title: Re: Fileread / Filewrite alternate
Post by: 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:
Title: Re: Fileread / Filewrite alternate
Post by: snowsnowsnow on July 16, 2015, 10:02:17 AM
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?
Title: Re: Fileread / Filewrite alternate
Post by: td on July 16, 2015, 10:26:27 AM
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.
Title: Re: Fileread / Filewrite alternate
Post by: snowsnowsnow on July 16, 2015, 10:31:56 AM
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?"
Title: Re: Fileread / Filewrite alternate
Post by: td on July 16, 2015, 10:40:05 AM
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.
Title: Re: Fileread / Filewrite alternate
Post by: stanl on July 16, 2015, 01:11:39 PM
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.
Title: Re: Fileread / Filewrite alternate
Post by: td on July 16, 2015, 02:04:31 PM
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.