我需要将路径(例如 C:\
)转换为该卷的 GUID 形式(例如 \\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\
).
C# 中是否有任何函数可以执行类似的操作?
最佳答案
您需要 P/Invoke GetVolumeNameForVolumeMountPoint
:
static string GetVolumeGuidPath(string mountPoint)
{
StringBuilder sb = new StringBuilder(50);
GetVolumeNameForVolumeMountPoint(mountPoint, sb, 50);
return sb.ToString();
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetVolumeNameForVolumeMountPoint(
string lpszVolumeMountPoint,
[Out] StringBuilder lpszVolumeName,
int cchBufferLength);
关于c# - 将路径转换为其 GUID 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25507996/