如何使用 Win32 API 删除目录限定符以简化路径名?
如果您有类似“C:\foo\.\bar\..”的路径,是否有一种简单的方法使用 Win32 API 删除目录限定符以将其简化为“C:\foo”?
更新:这似乎是一个更复杂的问题。在“C:\foo\.\bar\..”这个简单示例中,它与 PathCanonicalize() 和 GetFullPathName() 一起使用以获取“C:\foo”结果。
但是,我正在通过的路径有一个符号链接。假设我传入“C:\NaNa\Boo\Bin\..”,“C:\NaNa”是到“D:\Apple”的链接。然后我得到“C:\ NaNa \ Boo \ Bin \ ..”比“C:\ NaNa \ Boo”返回评级器
我假设这些函数仅适用于字符串,但使用符号链接时似乎存在差异: -(
更新#2:看来我在传入的字符串中有一个换行符(0x0d),这使得函数无法正常工作!
If you have a path like "C:\foo\.\bar\.." is there an easy way using the Win32 API to remove the directory qualifiers in order to simplify it to "C:\foo" ?
Update: It seems to be a more complicated issue. On this simple example of "C:\foo\.\bar\..", it works with both PathCanonicalize() and GetFullPathName() to get "C:\foo" as a result.
However, the path I'm passing has a symbolic link. So let's say I'm passing in "C:\NaNa\Boo\Bin\.." and "C:\NaNa" is a link to "D:\Apple". Then I get "C:\NaNa\Boo\Bin\.." back ratener than "C:\NaNa\Boo"
I would assume the functions work with just the strings but there seems to be a difference when using the symbolic link :-(
Update #2: It appears I had a line break character (0x0d) in the string that was passed in and this kept the function from working properly!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 shlwapi 的
PathCanonicalize()
Take a look at shlwapi's
PathCanonicalize()