binary vs. text?
Mark Schonewille
m.schonewille at economy-x-talk.com
Mon Dec 11 18:03:01 EST 2006
Chris,
When you import a file, you always want to do something with its
contents. Just check to see if the text contents fits the
destination. If not, it might be a binary file and you may need to
handle it differently.
There is another way. You could do a guess about the percentage of
spaces, returns, and alphanumerical characters in a normal text file
(nearly 100%) and in a binary file (significantly less). In those
cases that the actual percentage is lower than some treshold value,
assume it is a binary file. If the actual percentage is higher,
assume it is a text file. If the actual percentage is approximately
equal to the treshold value, ask the user.
You can store a copy of (a part of) the data in another variable, use
replaceText to remove all non-alfanumerical characters and calculate
the percentage. If you have a really large file, you don't need to
analyse the entire file.
Best,
Mark
--
Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz
Get your store on-line within minutes with Salery Web Store software.
Download at http://www.salery.biz
Op 11-dec-2006, om 23:09 heeft Chris Sheffield het volgende geschreven:
> 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.
>
> Any thoughts?
>
> Thanks,
> Chris
More information about the use-livecode
mailing list