具有以8.3缩写格式显示路径的网络位置。我需要将这些转换为在UNIX上使用的长格式。
由于它是一个网络位置,我需要它需要与UNC路径一起工作。
有什么想法吗?
发布于 2012-05-24 04:20:59
将短文本转换为长文本的答案是just a Google search away。这将适用于UNC路径only on Windows Vista and up (以及可能带有某些service packs的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());
}
}发布于 2015-12-23 18:51:31
即使使用C UNC路径,这对我也是有效的:
string shortName = @"\\MyComputer\c$\PROGRA~1";
string longName = new FileInfo(shortName).FullName;
// ==> longname: \\MyComputer\c$\Program Files https://stackoverflow.com/questions/10727182
复制相似问题