Skip to content

Instantly share code, notes, and snippets.

@Sohamkadam333
Created December 12, 2023 18:26
Show Gist options
  • Save Sohamkadam333/312e2430baef1c8d80319f7bb7696889 to your computer and use it in GitHub Desktop.
Save Sohamkadam333/312e2430baef1c8d80319f7bb7696889 to your computer and use it in GitHub Desktop.
Retrieves information about an object in the file system, such as a file, folder, directory, or drive root.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
CString filePath = L"E:\\samplefile.txt";
SHFILEINFO shfi;
ZeroMemory(&shfi,sizeof(shfi));
if(SHGetFileInfo(filePath,0,&shfi,sizeof(SHFILEINFO),SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME ))
{
// Display the retrieved information
_tprintf(_T("Display Name: %s\n"), shfi.szDisplayName);
_tprintf(_T("File Type: %s\n"), shfi.szTypeName);
DestroyIcon(shfi.hIcon);
}
else
{
cout<<"Error getting file info, Error no: "<<GetLastError()<<endl;
}
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment