关闭

c#.net下对获短路径

1035人阅读 评论(0) 收藏 举报

 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);

************************************

[DllImport("kernel32.dll")]
        static extern uint GetLongPathName(string shortname, StringBuilder   longnamebuff, uint buffersize);

public static string ToLongPathName(string shortName)
        {
            StringBuilder longNameBuffer = new StringBuilder(256);
            uint bufferSize = (uint)longNameBuffer.Capacity;

            GetLongPathName(shortName, longNameBuffer, bufferSize);

            return longNameBuffer.ToString();
        }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:115549次
    • 积分:1461
    • 等级:
    • 排名:千里之外
    • 原创:52篇
    • 转载:20篇
    • 译文:0篇
    • 评论:5条
    文章分类
    最新评论