将8.3文件名转换为长文件名

时间:2012-05-23 20:16:32

标签: c# .net filenames

拥有一个显示8.3短格式路径的网络位置。我需要将它们转换为长格式以便在UNIX上使用。

由于我需要它的网络位置,因此需要使用UNC路径。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

将短片换成长片的答案是just a Google search away。这适用于UNC路径only on Windows Vista and up(以及可能的XP w /某些服务包)。

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());
    }
}

答案 1 :(得分:1)

即使使用UNC路径,这对我也有用:

string shortName = @"\\MyComputer\c$\PROGRA~1";
string longName = new FileInfo(shortName).FullName; 
// ==> longname: \\MyComputer\c$\Program Files 
相关问题