-1

Say there are three types of file I want to distinguish, pure text file, JavaScript file, and VB script file. Given file has no extension, how do I tell the file type programmatically?

Xing Yan
  • 19
  • 4

1 Answers1

0

If the file types are text, as in the examples given, you would need to parse the file content to determine the file type, other file types have a predefined structure which includes headers, such as .dll and .exe files, which follow the PE format (COFF on nix systems).

BhavO
  • 2,406
  • 1
  • 11
  • 13
  • 1
    For text files (Javascript, VB, C#, etc) you can parse all, or at least a chunk of, the file and look for patterns/keywords in the text that would be visually recognizable as being JavaScript, VB, etc, etc. The logic could be fairly simple if you don't need it to be 100% accurate in all possible scenarios, or if you know of patterns/keywords which are always contained in one or the other and not both. – CSmanic Jul 07 '15 at 21:39
  • your welcome, please upvote if your happy? – BhavO Jul 08 '15 at 17:23