如何在 Windows 10 中获取逻辑驱动器名称? [英] How to get logical drives names in Windows 10?
问题描述
在 WPF 中,我们可以使用 System.IO 命名空间中的 GetLogicalDrives() 方法访问驱动器名称.但是对于 UWP,GetLogicalDrives() 方法不在 System.IO 命名空间中.那么如何在 Windows 10 中访问驱动器名称?
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?
推荐答案
不确定这是否能回答您的问题,但是:
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);
}
因此,对于名为ESD-USB"的 U 盘,这将返回您在资源管理器中看到的驱动器名称以及驱动器号,例如:ESD-USB (D:)"
.
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
位于 Windows.Storage
命名空间中.
KnownFolders
is in the Windows.Storage
namespace.
清单:更新评论中的问题
我已经有一段时间没有做这方面的工作了,所以不确定这是否是您需要做的全部.这是相关的清单信息:
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).
这篇关于如何在 Windows 10 中获取逻辑驱动器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!