WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: allalevkov on August 30, 2018, 05:42:19 PM

Title: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: allalevkov on August 30, 2018, 05:42:19 PM
Hi,
We receive files from the French company's main frame and it has *EOF* characters embedded in the names, which breaks the processing of the file in the middle.  The problem is that the program does not read past this character, so I cannot replace it.  The hex character we are getting is 1A. 

Any help would be greatly appreciated.
Alla
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: JTaylor on August 30, 2018, 06:15:42 PM
Have you tried the Binary Functions?   BinaryReplace() will handle any of the characters.

Jim
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: td on August 31, 2018, 07:53:20 AM
A crude example:

Code (winbatch) Select
strFile = 'c:\temp\EmbeddEof.txt'
strBuf = 'This file has an ':Num2Char(26):' in the middle':@crlf
; Creat a file with embedded EOF
FilePut(strFile, strBuf)

nSize = FileSize(strFile)
hBuf = BinaryAlloc(nSize*3)
BinaryReadEx(hBuf, 0, strFile, 0, nSize)
BinaryReplace(hBuf, Num2Char(26), 'EOF', 0)
strText = BinaryPeekStr(hBuf, 0, nSize)
BinaryFree(hBuf)


Message("File Text", strText)
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: allalevkov on August 31, 2018, 01:47:10 PM
Thank you very much!  My issue was Num2Char(26), did not know how to tell WB to replace '1A'.  Learned a lot about binary buffer use, great set of tools.  Here is what I ended with and it works:

   filename = 'C:\Develop\BadChar TEST File.txt'
   newfile  = 'C:\Develop\BadChar TEST File Fixed.txt'

debug(1)
   
   nSize = FileSize(filename)
   hBuf = BinaryAlloc(nSize+200)
   
   BinaryReadEx(hBuf, 0, filename, 0, nSize)
   BinaryReplace(hBuf, Num2Char(26), ' ', 0)
   
   BinaryWrite( hBuf, newfile )

   BinaryFree(hBuf)
Exit

I think to make a UDF out of it with IntControl(73...) just in case.  But that one is later.  Thank you all!
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: td on August 31, 2018, 02:36:40 PM
Another approach is to convert directly from the hex value to an ANSI character:

Code (winbatch) Select
strEof = ChrHexToString('1A')
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: allalevkov on August 31, 2018, 04:26:56 PM
Oh, this is great, as I have A4, A5, and expect some more.  Thank you!
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: td on September 04, 2018, 06:42:59 AM
If you have multiple characters to remove, you might consider using a combination of the FileGet and StrClean functions to perform the task in one pass over the file.
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: allalevkov on September 11, 2018, 11:55:17 AM
StrClean did not work while 1A was there, it would not go beyond 1A.  After it was removed StrClean should work, I will try it on the next change.
Thank you,
Alla
Title: Re: WinBatch: Need to convert junk EOF chars to spaces in the file
Post by: td on September 11, 2018, 01:15:46 PM
I have no problems getting StrClean to remove multiple characters in a file containing the 0x1a character.