Sarah Reichelt wrote:
On 12/12/06, Chris Sheffield <[EMAIL PROTECTED]> 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
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to