Search code examples
c#special-folders

C# SpecialFolders enumeration does not include Libraries Folder


The question title is seemingly straight forward and self-explanatory. The issue is that the SpecialFolders enumeration does not include Libraries Folder and I really need to access it and display its folders in a ListBox. Is there any way to do this please?


Solution

  • The path to the Libraries folder is %APPDATA%\Microsoft\Windows\Libraries, you can use SpecialFolder.ApplicationData, which on Windows is the same as the %APPDATA% environment variable:

    var appData = Environment.GetFolderPath(
            Environment.SpecialFolder.ApplicationData);
    
    var librariesFolder = Path.Combine(appData, @"Microsoft\Windows\Libraries");
    

    Another way to get the full path is to just expand the environment variable:

    var librariesFolder = Environment.ExpandEnvironmentVariables(
            @"%APPDATA%\Microsoft\Windows\Libraries");
    

    Anyways, this is Windows specific and won't work on other platforms, which is pretty much the single good reason to use Environment.SpecialFolder in the first place.