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

来源:互联网 发布:路由器有线网络不稳定 编辑:程序博客网 时间:2024/05/19 02:43
 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
原创粉丝点击