viewpoint-particle

Author Topic: WinBatch: Need to convert junk EOF chars to spaces in the file  (Read 101 times)

allalevkov

  • Newbie
  • *
  • Posts: 11
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
Life isn't about waiting for the storm to pass, it's about learning to dance in the rain! 
Author unknown to me

JTaylor

  • Pundit
  • *****
  • Posts: 914
    • Data & Stuff Inc.
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #1 on: August 30, 2018, 06:15:42 pm »
Have you tried the Binary Functions?   BinaryReplace() will handle any of the characters.

Jim

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #2 on: August 31, 2018, 07:53:20 am »
A crude example:

Code: Winbatch
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)
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


allalevkov

  • Newbie
  • *
  • Posts: 11
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #3 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!
Life isn't about waiting for the storm to pass, it's about learning to dance in the rain! 
Author unknown to me

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #4 on: August 31, 2018, 02:36:40 pm »
Another approach is to convert directly from the hex value to an ANSI character:

Code: Winbatch
strEof = ChrHexToString('1A')
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


allalevkov

  • Newbie
  • *
  • Posts: 11
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #5 on: August 31, 2018, 04:26:56 pm »
Oh, this is great, as I have A4, A5, and expect some more.  Thank you!
Life isn't about waiting for the storm to pass, it's about learning to dance in the rain! 
Author unknown to me

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #6 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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


allalevkov

  • Newbie
  • *
  • Posts: 11
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #7 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
Life isn't about waiting for the storm to pass, it's about learning to dance in the rain! 
Author unknown to me

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: WinBatch: Need to convert junk EOF chars to spaces in the file
« Reply #8 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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates