Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a way to tell a binary from a text file?
Message
De
20/01/2001 13:36:54
 
 
À
20/01/2001 13:29:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00464420
Message ID:
00466220
Vues:
18
>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

I think a more general approach would be to search for the occurance of a CHR(0) or CHR(26) other than at or beyond EOF() - those two are deinite no-nos for text files, while screen dumps of DOS boxes with line drawing characters might contain high ASCII.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform