Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 01-28-2009, 06:36 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default identifying file types

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.
BobLewiston is offline  
Old 01-28-2009, 10:12 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: identifying file types

Text or Binary? - CodeGuru Forums

Quote:
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.

office politics is offline  
Old 01-29-2009, 10:26 AM   #3 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: identifying file types

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.
__________________

Baez is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Ubuntu. 95BlackGA Linux, BSD, other *nixes & Open Source Software 1 10-16-2008 09:44 PM
A sneaky, and annoying virus donaldj HijackThis Logs (finished) 25 06-16-2008 08:58 PM
Possible Corrupted/Infected Files. xXxexpertxXx Virus - Spyware Protection / Detection 11 03-12-2008 01:18 AM
WTF is a Bad Block? MikesCreation Hardware Troubleshooting 18 02-24-2008 09:31 PM
Another Hijack Log boo HijackThis Logs (finished) 17 06-26-2007 12:30 PM