Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a way to tell a binary from a text file?
Message
From
20/01/2001 13:29:53
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00464420
Message ID:
00466214
Views:
15
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
Map
View

Click here to load this message in the networking platform