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
定义:
[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
本文介绍了一个使用 C# 调用 Win32 API 方法 GetShortPathName 的示例,该方法用于将长文件路径转换为短文件路径。通过具体的代码实现展示了如何将一个长路径(例如 F:/1234567891.jpg)转换成对应的短路径(例如 F:/123456~1.jpg)。
988

被折叠的 条评论
为什么被折叠?



