Search code examples
c#windowsfile-type

Given a file without extension, how to determine the type of that file


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?


Solution

  • 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).