短文件名(经常用到)

来源:互联网 发布:android中json解析 编辑:程序博客网 时间:2024/04/27 18:54

public static string ToShortPathName(string longName)
  {
   StringBuilder shortNameBuffer = new StringBuilder(256);
   int bufferSize = shortNameBuffer.Capacity;

   int result = GetShortPathName(longName, shortNameBuffer, bufferSize);

   return shortNameBuffer.ToString();
  }
  [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  public static extern int GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string path,[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,int shortPathLength);
 

原创粉丝点击