Detect file type?
How would I detect the filetype of a file?
Thanks,
paoloTheCool
How would I detect the filetype of a file?
Thanks,
paoloTheCool
Getting extension and finding out file type is completly different. I could save a file with a ".jpeg" when it is really a ".ico" file.
Thanks,
paoloTheCool
For files that contain a header (e. g. .bmp, .wav), you can open the file and examine it to determine it. For files that don't have a header (e. g. .txt), then you will have to come up with some other way to do it.
Usually the file's extension identifies the file type. If you don't trust that, then you will have to examine the file.
Chris
The only two ways is to go by header (or footer in some cases) or by file extention. I could go create my own file type with a specific format, no header, and call it a sff. How would you expect to know what this is? It could be something like a xaml file where analysis of it (ignoring any headers) would tell you it might be a text file... or a xml file... or a xaml file...
I think you should stick to file extention, then check file types with tag information for the prescense of the proper tagging. If the file extention fails, you can check for tags. However if the tag checks fail treat it as unknown (my only slight clarification of Chris' explanation).
What is your goal in checking for file type?
Ok...so I guess there's no easy method for accuratly detecting the file type easily. I'll just use extensions.
Thanks,
paoloTheCool