Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine if a file is text or binary 2

Status
Not open for further replies.

KarveR

MIS
Dec 14, 1999
2,065
GB
There has to be a way, could someone point me in the right direction please?

So far I think I've read and re-read
File IO
StreamWriter
FileStream
Attributes
fileinfo

6 or 7 forums searched, googled and generally gone (a little more) bald.

Am I missing something so horrendously obvious here, or is this the holy grail.

-* reason: I want to search text files and have absolutely no need of searching stuff that isn't plain text.

*additional, also rummaged around with Ifilters too, but thats a tad heavy duty for my present requirements.







______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
There's nothing in the framework which will do this for you automatically.

Some strategies I've seen used in the past:

1) Read the first 1000 bytes and see what percentage of non-printable characters it contains

2) Have a list of known file extensions

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks Chip, I can't believe they'd overlook something so useful but the more I read, the more I see there are alot of things which would be incredibly useful which aren't included.

The newer version shows some improvements from the looks of the docs (read alot of thse too) but I d't have that.

I'll give your suggestions a shot, thanks again.

kev

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The reason it's not in the framework is that there's no 100% sure way to tell. Both of the above strategies are subject to failure:

1) The binary part of the file might not start until after the part you scan

2) The user might have renamed a .xls file to a .txt file

So, if it's not 100% certain, it shouldn't be in the framework.

Which is not to say that you couldn't write a .net library and sell it as a binary file detector. You'd have some good upgrade revenues whenever new filetypes get introduced. :)

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
food for thought, and in need of some real direction while I learn, that could be an avenue worth exploring :)

It hasn't been to painful moving from PHP (and some dusty memories of C+) but I still foresee many hours of head-in-book ahead of me.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks earth ... that will score a direct hit on an entirely unrelated PHP project :D

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Anything to help a fellow Bristolian [smile] - there is also another excellent site but its not in my favourites list and I can't remember what it is for the moment. If I track it down over the weekend I'll repost.

[vampire][bat]
 
Thanks matey, where in Bristol - I lied a little, am in Thornbury really :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I'll let you off as its got a BS postcode. I live in Bedminster and work in Swindon (when I can't get away with working from home - VPN is a wonderful thing)

[vampire][bat]
 
I gave up working in Swindon years ago, the drive sux, although I understand theres a fair bit of work out that way.

Now if I need to work other than in the office, I have a minimum drive of 87 miles rising to near 400.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top