binary vs. text?

Geir A. Myrestrand geir.myrestrand at falconstor.com
Mon Dec 11 17:46:54 EST 2006


Sarah Reichelt wrote:
> On 12/12/06, Chris Sheffield <cmsheffield at gmail.com> wrote:
>> Does anyone have a sure fire way to determine if a file is binary or
>> text?
>>
>> I have need to create an import utility that will import data from a
>> text file (csv, tab-delimited, etc) into a database, but I'd like to
>> check the file before doing anything else just to make sure it is in
>> fact text and not binary.
> 
> 
> Just a guess here but how about reading the file twice: once as file:
> and once as binfile:
> If the two are identical, then I assume it's text only.
> 
> I have no idea if this will work, but it's worth a try :-)
> Sarah

The solution won't scale, and it also depends whether it would handle 
multi-byte characters (use for Kanji for example) and certain UNICODE 
formats that use the NULL character.

If this is on a particular platform, then there are various ways to do 
this. On Linux/UNIX systems you can run `file <filename>` in order to 
classify a file for example.

-- 

Geir A. Myrestrand



More information about the use-livecode mailing list