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?
Asked
Active
Viewed 1,138 times
-1
-
1Javascript and VB script files *are* text files... – neminem Jul 07 '15 at 21:32
-
The only approach is to parse file content so as to identify if the syntax may correspond to Javascript or VB script. Otherwise, the file shall be considered as plain text. – Graffito Jul 07 '15 at 21:36
-
possible duplicate of http://stackoverflow.com/questions/58510 – Mark Tomlinson Jul 07 '15 at 21:42
1 Answers
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
-
1For 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
-