如何检查2的DirectoryInfo对象是否指向同一目录? [英] How to check whether 2 DirectoryInfo objects are pointing to the same directory?

查看:79
本文介绍了如何检查2的DirectoryInfo对象是否指向同一目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2 的DirectoryInfo 对象,并要检查,如果他们都指向同一个目录。除了比较他们的全名,还有没有其他更好的方法来做到这一点?请忽略链接的情况。

I have 2 DirectoryInfo objects and want to check if they are pointing to the same directory. Besides comparing their Fullname, are there any other better ways to do this? Please disregard the case of links.

下面就是我的。

DirectoryInfo di1 = new DirectoryInfo(@"c:\temp");
DirectoryInfo di2 = new DirectoryInfo(@"C:\TEMP");

if (di1.FullName.ToUpperInvariant() == di2.FullName.ToUpperInvariant())
{ // they are the same
   ...   
}

感谢。

推荐答案

在Linux下你可以比较两个文件wheather它们是相同的inode号。但在Windows下没有这样的概念,至少不是,我知道了。您需要使用的P / Invoke解决的链接(如有)。

Under Linux you could compare the INode numbers of the two files wheather they are identical. But under Windows there is no such concept, at least not that I know off. You would need to use p/invoke to resolve the links if any.

比较字符串就是你能做的最好的。请注意,使用的String.Compare(STR1,STR2,StringComparison.InvariantCultureIgnoreCase)是有点比你快接近

Comparing strings is the best you can do. Note that using String.Compare(str1, str2, StringComparison.InvariantCultureIgnoreCase) is a bit faster than you approach.

这篇关于如何检查2的DirectoryInfo对象是否指向同一目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆