功能萎缩文件路径更加可读 [英] Function to shrink file path to be more human readable
本文介绍了功能萎缩文件路径更加可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有在C#中SHINK任何功能文件路径
Is there any function in c# to shink a file path ?
输入:C:\users\Windows\下载的程序Files\Folder\Inside\example\file.txt
Input: "c:\users\Windows\Downloaded Program Files\Folder\Inside\example\file.txt"
输出:C:\users\ ... \example\file.txt
Output: "c:\users\...\example\file.txt"
推荐答案
杰夫阿特伍德的公布解决这个在他的博客,在这里它是:
Jeff Atwood posted a solution to this on his blog and here it is :
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
static extern bool PathCompactPathEx([Out] StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
static string PathShortener(string path, int length)
{
StringBuilder sb = new StringBuilder();
PathCompactPathEx(sb, path, length, 0);
return sb.ToString();
}
它采用了非托管函数的 PathCompactPathEx
达到你想要的东西。
It uses the unmanaged function PathCompactPathEx
to achieve what you want.
这篇关于功能萎缩文件路径更加可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文