【发布时间】:2012-05-23 20:16:31
【问题描述】:
拥有一个以 8.3 短格式显示路径的网络位置。我需要将这些转换为长格式以便在 UNIX 上使用。
由于它是一个网络位置,我需要它使用 UNC 路径。
有什么想法吗?
【问题讨论】:
拥有一个以 8.3 短格式显示路径的网络位置。我需要将这些转换为长格式以便在 UNIX 上使用。
由于它是一个网络位置,我需要它使用 UNC 路径。
有什么想法吗?
【问题讨论】:
将short 转换为long 的答案是just a Google search away。这适用于 UNC 路径 only on Windows Vista and up(以及可能带有一些服务包的 XP)。
using System;
using System.Runtime.InteropServices;
using System.Text;
public class _Main
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetLongPathName(
string path,
StringBuilder longPath,
int longPathLength
);
public static void Main()
{
StringBuilder longPath = new StringBuilder(255);
GetLongPathName(@"\\?\UNC\server\d$\MYTEMP~1\RESOUR~1\sql.txt", longPath, longPath.Capacity);
Console.WriteLine(longPath.ToString());
}
}
【讨论】:
即使使用 UNC 路径,这也适用于我:
string shortName = @"\\MyComputer\c$\PROGRA~1";
string longName = new FileInfo(shortName).FullName;
// ==> longname: \\MyComputer\c$\Program Files
【讨论】: