本文介绍了与正常化文件WinAPI的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  Best方法来确定两个路径引用在C相同的文件/ C ++

由于具有潜在不同的外壳和斜线两种文件路径字符串('\\' VS /),有一个快速的方法(不涉及写我自己的功能),以两个路径正常化同样的形式,或至少以测试它们等价?

Given two file path strings with potentially different casing and slashes ('\' vs '/'), is there a quick way (that does not involve writing my own function) to normalize both paths to the same form, or at least to test them for equivalence?

我只限于WinAPI的和标准C ++。所有文件都是本地的。

I'm restricted to WinAPI and standard C++. All files are local.

推荐答案

根据不同的路径是否可以是相对的,或者包含..,或交接点,或UNC路径,这可能比你想象的更困难。最好的办法可能是使用的 GetFileInformationByHandle()的功能在this回答。

Depending on whether the paths could be relative, or contain "..", or junction points, or UNC paths this may be more difficult than you think. The best way might be to use the GetFileInformationByHandle() function as in this answer.

编辑:我同意RBerteig评论,这可能变得很难做不成如果路径没有指向本地文件。如何安全地处理这种情况的任何评论将大大AP preciated。

I agree with the comment by RBerteig that this may become hard to impossible to do if the paths are not pointing to a local file. Any comment on how to safely handle this case would be greatly appreciated.

这篇关于与正常化文件WinAPI的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:15
查看更多