Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,


Is there any function call or the code block to get the file type.
I could have used the last three char like for "a.txt" can identify as text file.
But this doesn't work when the check box in the folder options i.e."Hide extension for known file types" is checked.

PS

I need this code for filtering of the files in CMFCShellListCtrl based on file types.
Posted

First thing to understand: even though the term "extension" is often used, there is no extensions in modern file systems like NTFS. This is no more than a tradition to classify the files by the types of their applications by their file name ending in the form of dot followed by three (sometimes more) other characters. In older file systems, the "extension" was an attribute of a file.

Now, the option "hide extension for known file types" is related only to one program: Windows Explorer. If you change this option, it won't change anything at all, not even Shell behavior: if you use some other program using exact same Shall API as Explorer does, nothing will change if this option is changed.

So, there is no such problem per se. You probably have some different problem not related to what you think it is related. This is some problem: you should ask question without using your idea on how it should be solved your might be preoccupied with. You should always explain your ultimate goals and describe the behavior you want to implement and why. In this case, if you explain how your filtering should work and what's the purpose of this filtering, you can get a change to receive some positive advice. I cannot give you such advice as I don't know what exactly you want to achieve.

[EDIT]

Just a hint. You may need to learn how file types are registered in the system Registry. See this discussion: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/630ed1d9-73f1-4cc0-bc84-04f29cffc13b[^].

—SA
 
Share this answer
 
v2
Comments
abhishek.biradar 23-Jan-12 0:02am    
My requirement is very easy. I am using CMFCShellListCtrl for selecting the files.
when "hide extension for known file types" is unchecked, The CMFCShellListCtrl returns selected files with extension i.e. a.txt,b.pdf etc
When "hide extension for known file types" is checked , The CMFCShellListCtrl returns selected files without extension i.e. only a a,b etc.
My actual requirement is I should get to know the type of file irrelevant to "hide extension for known file types" is checked or unchecked. So depending on the extensions doesn't work.
I just wanted to know if there is any function which takes file path as argument and return the file type like PDF,TXT etc.
Sergey Alexandrovich Kryukov 23-Jan-12 1:38am    
Understood. I already answered. Let's see what can be inferred from this answer:

1) Using the flag "hide extension for known file types" makes no sense as it is private to the particular application -- Windows Explorer. Even if you pull this information somehow, Microsoft cannot guarantee it will be maintained, so don't even try. I would recommend: 1a) use the same kind of flag, but introduce it in your application, 1b) much better: always show full name; don't you think the option of hiding is idiotic? it does not help any one; people use it only because they are lazy enough or don't care about changing the default.

2) You can pull this information from system Registry if you find out how from the discussion I referenced. This is fairly simple thing. You can probably find some code sample doing something similar. I would strongly advise not to bother about it and use the most reasonable option (1b).

At this moment, I think my answer is complete.
If you agree, please accept it formally (greed button) -- thanks.

Good luck.
--SA
 
Share this answer
 
Comments
Lakamraju Raghuram 23-Jan-12 1:15am    
The question is related to C++/VC++/MFC (see those tags)
Is the above link satisfy that [I think it has something to do with .NET (: ]

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