How to reference the C:\Users\Public directory programmatically in C#

前端 未结 6 959
日久生厌
日久生厌 2021-01-04 00:33

Is it safe to programmatically reference the public folder through:

Directory = System.Environment.GetEnvironmentVariable(\"public\")+\"MyCompanyName\" // et         


        
6条回答
  •  清歌不尽
    2021-01-04 01:04

    You can get all these %wildcard% literals by looking into

    Windows->Start-->regedit-->

    Then, you perform

    using System;
    string path2Downloads = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Downloads");
    
    string path2Music = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Music");
    

    ... and, so on .... and to test:

    using System.IO;
    
    string[] files = { "" };
    if (Directory.Exists(path2Music)) {
        files = Directory.GetFiles(path2Music);
    }
    

提交回复
热议问题