Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将路径与“路径”进行比较;“我的文件”;及;文件;在他们里面?_C#_.net_Windows - Fatal编程技术网

C# 如何将路径与“路径”进行比较;“我的文件”;及;文件;在他们里面?

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)

我正在使用Windows搜索服务(Provider=Search.CollatorDSO)在
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)?

可能的重复路径