且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文件的长路径如何转换为短路径(dos格式)

更新时间:2022-09-10 14:47:46

using System.Runtime.InteropServices;

定义:
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength);

引用:
StringBuilder shortPath = new StringBuilder(80);
int result = GetShortPathName(
@"F:\1234567891.jpg", shortPath, shortPath.Capacity);
string s = shortPath.ToString();
MessageBox.Show(s.ToString());

结果:
F:\123456~1.jpg

转自csdn




本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/08/31/1557319.html,如需转载请自行联系原作者