WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on November 18, 2026, 05:57:04 AM

Title: Segway from UTF-8 thread
Post by: spl on November 18, 2026, 05:57:04 AM
Tony,

You referred to the WIl FileEncoding() function to detect if a file could be UTF-8 w/out BOM. But one of the options was to detect a binary file. Not sure which version of WB that function appeared in or if it was always just a hidden gem. Anyway --- I looked over some code I wrote (decades ago) where to detect a binary file, I used a list to detect extensions
binfile = '.com', '.exe', '.dll', '.bin', '.iso', '.zip', '.tar', '.rar', '.7z', '.gz', '.pdf', '.epub', '.mobi','.azw','.azw2','.azw3'

which is, of course, imperfect but useful back then. I would assume your function, in addition to determining BOM bytes, would use the Windows API for GetBinaryType() from Kernel32, but maybe some other magic. Anyway - assume the function works and detects binary. How might one expand it to determine the type of binary, for example

A 32-bit Windows-based application, SCS_32BIT_BINARY
An MS-DOS - based application, SCS_DOS_BINARY
A 16-bit Windows-based application, SCS_WOW_BINARY
A PIF file that executes an MS-DOS based application, SCS_PIF_BINARY
A POSIX based application, SCS_POSIX_BINARY
A 16-bit OS/2-based application, SCS_OS216_BINARY
A 64-bit Windows-based application, SCS_64BIT_BINARY

This is not an ask for a WB improvement, more just for your opinion. I doubt anyone who even reads this far cares, but you have knowledge and insight that in spite as how ornery I appear I appreciate and respect.