identifying file types

Status
Not open for further replies.

BobLewiston

In Runtime
Messages
182
Within a C# program, is there any way to tell if a file is a text file or not? I mean a real way, not just basing your conclusion on a file name extension.
 
Text or Binary? - CodeGuru Forums

mr. blonde
Member Join Date: Aug 2000
Posts: 393

Re: Text or Binary?

--------------------------------------------------------------------------------

EXE's always start with "MZ". Beyond that you can do a character frequency analysis on the file. Binary files will yield a more random pattern, while a text file will be almost entirely printable ASCII. I have code somewhere that does such a thing if you're interested, though it's in QBASIC.
 
Most file formats start with some kind of ASCII character or word at the beginning of the file. Like wave files use the word RIFF as its first 4 characters. That would be the way you can tell.
 
Status
Not open for further replies.
Back
Top Bottom