954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

reading file types

is there a way i can look at a file and see its type. i need to make a program that scans files and determins if the file extenstion is correct based on the actual file type.
this, for example, would find a ".zip" file hidden with a ".jpg" extension
any ideas?

plazmo
Posting Whiz in Training
207 posts since Aug 2005
Reputation Points: 23
Solved Threads: 16
 

i don't think so, at least not easily. all files are basically just a long string of bytes. The extension tells windows (or whatever OS you are using) what to do with that string. By changing the extension, say from .jpg to .txt, you are, in essence, making that jpg into a text file. Now certain extensions are expected to have certain formats and probably will not work properly if you change the extension. But other than doing a bytewise scan looking for certain patterns, which would be beyond my skill level, I don't think there is a way to do what you want. Any more experienced programmers have any ideas? Or am I completely full of you know what here?

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You