最近在网上看到,系统传递的文件路径有时是DOS形式的短文件名,有人给出了C++的解决方法。下面我列出了C#的方法:
using System.IO;
private static string GetLongPathName(string Short)
{
DirectoryInfo pdi = new DirectoryInfo(Short);
string rt = "";
while(pdi.Parent != null)
{
string [] tmp = Directory.GetDirectories(pdi.Parent.FullName,pdi.Name);
DirectoryInfo di = new DirectoryInfo(tmp[0]);
rt = Path.Combine(di.Name,rt);
pdi = pdi.Parent;
}
rt = Path.Combine(pdi.Root.Name,rt);
return rt;
}