C #: How can I get a description of a folder?

All folders are of type: most of them have the name "folder with files", but some of them are called "Mediaserver" or "Local harddrive" (translations). How to get these types of folders using C #? I found this for files: How to get a description of a file extension in .NET

+8
c #
source share
2 answers

SHGetFileInfo is a necessary function. You need to pass the FILE_ATTRIBUTE_DIRECTORY flag as a parameter to the dwFileAttributes parameter.

Based on the same answer you linked . I changed the code to work for directories.

 public static string GetFileFolderTypeDescription(string fileNameOrExtension) { SHFILEINFO shfi; if (IntPtr.Zero != SHGetFileInfo( fileNameOrExtension, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY, out shfi, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME)) { return shfi.szTypeName; } return null; } 
+14
source share

Each folder has a file called desktop.ini that contains a description of the translated folder and an icon for the folder in the INI file format. You might need to read this.

I found that for system folders this refers to resources in system DLLs, so this may not be as simple as it seems.

You can also try SHGetFileInfo to get this information.


I just saw that Sriram Sahtivel gave a very good answer using SHGetFileInfo , so go for it.

+5
source share

All Articles