C# 如何将路径与“路径”进行比较;“我的文件”;及;文件;在他们里面?
我正在使用Windows搜索服务(Provider=Search.CollatorDSO)在C# 如何将路径与“路径”进行比较;“我的文件”;及;文件;在他们里面?,c#,.net,windows,C#,.net,Windows,我正在使用Windows搜索服务(Provider=Search.CollatorDSO)在c:\users\taras\documents\中查找文件。 输出文件路径如下所示:C:\Users\taras\My Documents\\\。现在我需要得到相对路径,但首先我必须规范化路径 我试着这样做: string itemPath = new FileInfo(filePath).FullName; string repoPath = new DirectoryInfo(repository)
c:\users\taras\documents\
中查找文件。输出文件路径如下所示:
C:\Users\taras\My Documents\\\
。现在我需要得到相对路径,但首先我必须规范化路径
我试着这样做:
string itemPath = new FileInfo(filePath).FullName;
string repoPath = new DirectoryInfo(repository).FullName;
但是itemPath
仍然有“我的文档”,而repoPath
仍然有“文档”
现在我这样做:
string itemPath = filePath.ToLower().Replace("\\my documents\\", "\\documents\\");
string repoPath = repository.ToLower().Replace("\\my documents\\", "\\documents\\");
它可以工作,但看起来很奇怪,对Windows目录的其他类似情况没有帮助
在比较之前,有没有办法规范化路径(替换simlinks)?可能的重复路径