question

Adelto-3018 avatar image
0 Votes"
Adelto-3018 asked Adelto-3018 answered

How to get a list of file type information

There are several types of files in Windows.

And directory browsers display a description of each file type.

For example, a string such as "Video File", "Audio File", "Zip Compressed File", "Text File", etc.

I need a list of descriptive strings for file types stored in Windows, using C++.

Is there a way to get a list using C++?

I know how to get the information about each file using the SHGetFileInfoW function.

But what I need is a list of information, not individual information.

The application I'm creating now needs to list all files on Windows, and needs to sort the files based on the information above.

But SHGetFileInfoW function is too slow.

So I need to get the list in advance.



Thanks for reading this text.



PS I can't speak English well.

windows-apic++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered

That is not as simple as you may think, as there are some
types that are defined by standards organizations, some are
proprietary - defined by private corporations, some that are
purely arbitrary - such as those chosen by individual
developers, etc. See for example:

File Types
https://docs.microsoft.com/en-us/windows/win32/shell/fa-file-types

Perceived Types (The Windows Shell)
https://docs.microsoft.com/en-us/windows/win32/shell/fa-perceivedtypes

List of file formats
https://en.wikipedia.org/wiki/List_of_file_formats

While a file's extension may identify the file type

https://www.file-extensions.org/

note that different file types may use the same
extension. Also, a file's actual type may only
be identified by examining the file's contents
such as its header data.

It is a common trick used by malware distributors
to give a file a false extension to hide its real
purpose. For example trying to make an exe appear
as a pdf file thereby luring victims into running it.

So you are pretty much constrained to use the file
types that are registered with Windows.

  • Wayne



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PetrusKIM-2099 avatar image
0 Votes"
PetrusKIM-2099 answered

Some File Extension is in the Registry (HKEY_CLASSES_ROOT)
You can get the information like this, but not enough.

 void RetrieveFromReg()
 {
 #define MAX_KEY_LENGTH 255
     HKEY    hRootKey        = NULL;
     HKEY    hSubKey            = NULL;
    
     DWORD    dwSubKeyCount    = 0;
    
     TCHAR   szSubKey[MAX_KEY_LENGTH]    = { 0x00 };
     TCHAR    szData[MAX_KEY_LENGTH]        = { 0x00 };
        
     DWORD    dwSize            = MAX_PATH;
    
     if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, nullptr, 0, KEY_READ, &hRootKey))
     {
         if (ERROR_SUCCESS == RegQueryInfoKey(hRootKey, NULL, NULL, NULL, &dwSubKeyCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
         {
             if (dwSubKeyCount)
             {
                 for (DWORD i = 0; i < dwSubKeyCount; ++i)
                 {
                     dwSize = MAX_KEY_LENGTH;
                     if (ERROR_SUCCESS == RegEnumKeyEx(hRootKey, i, szSubKey, &dwSize, NULL, NULL, NULL, NULL))
                     {
                         if (ERROR_SUCCESS == RegOpenKeyEx(hRootKey, szSubKey, 0, KEY_READ, &hSubKey))
                         {
                             dwSize = MAX_KEY_LENGTH;
                             RegGetValue(hSubKey, NULL, NULL, RRF_RT_ANY, NULL, szData, &dwSize);
    
                             RegCloseKey(hSubKey);
                         }
                     }
                 }
             }
         }
         RegCloseKey(hRootKey);
     }
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Adelto-3018 avatar image
0 Votes"
Adelto-3018 answered

I've found a way.
Thank you all for your answers.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.