WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: KeithW on September 08, 2025, 02:18:14 PM

Title: Text File EOL Processing
Post by: KeithW on September 08, 2025, 02:18:14 PM
I am not sure what else to use off hand, the following code was an attempt to determine what kind of source OS generated the text file...  for MAC EOL is a CR, *nix system LF and DOS/Windows CRLF but in this code the LF is always gobbled so it appears to be a MAC based text file even though it was generated on Windows. What else can I use to properly determine EOLs correctly.

   DataLine = FileGet(fileToRead)
   Message("DataLine is", DataLine)
   EOLCHK = strsub(Dataline,(strlen(dataline)-2),2)
   Message("*EOLCHK",">...":ChrStringToHex(EOLCHK):"...<")
   if (strsub(EOLCHK,2,1) == @LF && StrSub(EOLCHK,1,1) == @CR) then Message("DOS/WIN EOL"," CR/LF ")
   if (strsub(EOLCHK,2,1) == @LF && StrSub(EOLCHK,1,1) != @CR) then Message("*NIX EOL", "Just a LF")
   if (strsub(EOLCHK,2,1) == @CR && StrSub(EOLCHK,1,1) != @CR) then Message("MAC EOL","Just a CR")

Regards,
Keith
Title: Re: Text File EOL Processing
Post by: td on September 09, 2025, 09:12:38 AM
The line EOLCHK = strsub(Dataline,(strlen(dataline)-2),2) should be EOLCHK = strsub(Dataline,(strlen(dataline)-1),2).
Title: Re: Text File EOL Processing
Post by: KeithW on September 09, 2025, 10:32:59 AM
Duh, sorry, I should have caught that...


T H A N X !!