Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys,
Please I need help,

How can I programmatically determine the type of the file like windows File Properties.
For example: Type of file: Application, Service or Batch File,etc...

Please take a look:
http://www.fileswap.com/dl/Bjca9UhkRG/


Thanks in advance...
Posted

What Windows does there is look at the file extension and then look in the registry to decide what kind of file it is, and what application processes it. That info can include "Content Type" key, which describes the file type.

To duplicate this, you would have to do the same thing, or use the SHGetFileInfo: This may help: http://stackoverflow.com/questions/3780028/how-can-i-get-the-description-of-a-file-extension-in-net[^]
 
Share this answer
 
Comments
Maestro-Pc 8-Mar-14 5:50am    
Hi many thanks for your reply, I've used SHGetFileInfo API and it's working perfectly...
OriginalGriff 8-Mar-14 5:56am    
You're welcome!
Maciej Los 8-Mar-14 14:18pm    
Well explained ;)
+5
Strictly speaking, there is no such thing as "extension". This is some historical casus: in some old systems, there was an "extension" to the name of the file, which wasn't a part of the name. Presently, there is just the name; and there are naming conventions which are not mandatory and no longer effect any functionality. In Windows shell, those "extension" can be used for recognition of the "file types" recorded in the Registry where it is prescribed what operations can be performed at the Shell level for what file, using what application, with what command line.

No, without "extension", you cannot recognize those types. But even with "extension", it is often impossible. There is no any kind of OS-level universal mechanism. The rules for "extensions" are no rules; this is very loose mechanism. The same "extension" can be used for different formats and visa versa, or "extensions" not completely describe the type, as in case of media files. For an application, it can be a multi-step process. The file is attempted to open, the application looks at file signature (some first bytes at the very beginning), then examine "file header", and so on… There is nothing absolutely universal. Anyway, the OS does not care about it; you may need to develop your own file formats for your own applications, and so on…

Windows Explorer file name is not "explorer" as it looks on you picture; it is actually "Explorer.EXE". Look thoroughly. Remove the stupid "Folder Options" option "hide extension of known types".

—SA
 
Share this answer
 
v3
Comments
Maciej Los 8-Mar-14 14:18pm    
Well explained ;)
+5
Sergey Alexandrovich Kryukov 8-Mar-14 14:29pm    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900