gpt4 book ai didi

c# - 将路径转换为其 GUID 形式

转载 作者:行者123 更新时间:2023-11-30 14:10:08 25 4
gpt4 key购买 nike

我需要将路径(例如 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com