3 ms·
The 'correct' way to determine the type of a file is indeed to look at metadata. This includes things like magic numbers and extensions, but shouldn't be limite
by yew 13y ago
The 'correct' way to determine the type of a file is indeed to look at metadata. This includes things like magic numbers and extensions, but shouldn't be limited to those things.
Just looking at extensions can be misleading because not all files have extensions and some extensions correspond to multiple types of files. In general, no method will be perfect because no modern OS provides dedicated file typing (some older operating systems stored the file type as metadata, although even that breaks down at the boundary between your computer and the rest of the world). The imperfection is usually manageable, depending on the type of file (which is the real answer to your question - it depends on why you want to know).
Applications that won't open what I tell them to because they disagree about the file type are just broken. (Having to rename files whenever I want to open them is annoying. Having to replace a good piece of software because it refuses to follow instructions is even more annoying.)