0

I have been reading about this topic, but the answers doesn´t solve my problem, and all of this are from some years ago.

What i am trying to do is to know a file type with not extension available. I.e. if i have a ".csv" file, and replace this extension by ".txt", or directly if the extension doesn´t appear in the name ¿exist any way to know the real extension?

Thanks!

1 Answers1

3

Unfortunately, there is no portable way to do this. Some file systems traditionally use "magic bytes", as stated by Equalsk, some platforms use extensions, and some use metadata in the file system. Unfortunately, due to the ubiquity of Windows (and DOS before it) the extension is the primary means these days. MIME helps a little, but that's only transport. The only way to even begin to guess the contents of a file is to look for patterns inside - the magic bytes. And this is fallible.

Keith Douglas
  • 102
  • 1
  • 8