How to get logical drives names in Windows 10?

只谈情不闲聊 提交于 2019-12-11 11:51:59

问题


In WPF, we can access the drives names using GetLogicalDrives() method in System.IO namespace. But for UWP, GetLogicalDrives() method is not in System.IO namespace. So how can I access drives names in windows 10?


回答1:


Nor sure if this answers your question, but:

var removableDevices = KnownFolders.RemovableDevices;
var folders = await removableDevices.GetFoldersAsync();

This will return a collection you can iterate through:

foreach (StorageFolder folder in folders)
{
  sb.AppendFormat("DisplayName: {0}", folder.DisplayName);
}

So for a USB stick called "ESD-USB" this will return the name of the drive you see in Explorer along with the drive letter, e.g: "ESD-USB (D:)".

KnownFolders is in the Windows.Storage namespace.

Manifest: Update for question in comments

It's a while since I did any work on this, so not sure if this is all you need to do. Here's the relevant manifest info:

Under Capabilities I have the following ticked: Removable Storage, Pictures Library, Music Library, Videos Library, Internet (Client).



来源:https://stackoverflow.com/questions/37404405/how-to-get-logical-drives-names-in-windows-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!