2013-04-12 62 views
10

如何獲取添加到「我的音樂」中的所有庫位置?獲取資源管理器庫中的所有目錄

在這個例子中,我已經添加了這些目錄庫:

E:\My Music 
E:\Mp3 

我想:

Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); 

但它返回:

C:\Users\MyUser\Music 

+0

如果只有兩個文件夾存在,您可以手動逐個添加目錄嗎? –

+1

我有很多的目錄添加到我的圖書館位置,所以逐個添加它不是我的選擇.. :) –

+2

你已經爲你做好了你的工作,但這是一個很好的例子。 http://www.codeproject.com/Articles/143038/Parsing-Windows-7-Libraries-Without-NET-4-or-the-W –

回答

1

添加到媒體播放器的任何庫都應該在AppData目錄中。

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\Libraries\Music.library-ms" 

也許這會有所幫助。

0

我做這個其他StackOverflow的問題相似,posted a full solution with code using Windows API Code Pack東西。在你的情況,你會發現,上面寫着代碼:

 ICollection<IKnownFolder> allSpecialFolders = Microsoft.WindowsAPICodePack.Shell.KnownFolders.All; 

然後遍歷這些文件夾中找到適合您的需要之一:

string fpath = ""; 
    // Iterate over each folder and find the one we want 
    foreach (var folder in allSpecialFolders) 
    { 
     if (folder.ParsingName == foldername) 
     { 
      // We now have access to the xml path 
      fpath = folder.Path; 
     } 
    } 

    if (fpath == "") 
     return null; 

    var intFolders = GetLibraryInternalFolders(fpath); 

    return intFolders.Folders.ToList(); 

然後使用GetLibraryInternalFolders()函數返回裏面有多個文件夾。無論如何,請在另一個問題上查看我的完整代碼解決方案。

相關問題