General information
Category:
Coding, syntax & commands
I don't know of any quick and dirty way to tell a binary from a text file. As you know, DOS/Windows files aren't coded by file type.
I'm assuming your're not talking about Unicode files but "normal" ASCII files containing one byte per character.
However, I guess it depends on your definition of binary file. If you accept my definition then here's a chunk of code that will work fairly well but may be a little slow on large files. Of course, it's easily modifiable.
* IsBinary() - Return .T. if the passed file contents is binary
FUNCTION IsBinary( cContents )
LOCAL nX, cChar
* A binary file is one that contains characters from CHR(127)-7Fh or
* higher. But, some languages use characters from CHR(128)-80h thru
* CHR(168)-0A9h so we'll ignore those.
* Look for each of these characters in the file's contents
FOR nX = 127 TO 255
IF nX = 128
nX = 168
LOOP
ENDIF
cChar = CHR(nX)
IF cChar $ cContents
RETURN .T.
ENDIF
ENDFOR
RETURN .F.
ENDFUNC
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only