获取两个文件之间的相对路径的最佳/最简单/最快方法?
我正在重构一些 C# 代码,其中一部分是重做一些引用,因为我们正在完全重做文件夹结构。 我想做的只是进入 .csproj 或 .sln 文件并修改路径。
然而,一些参考文献具有类似的路径
"../../../../../../ThirdParty/SomeMicrosoftLibrary/bin/Debug/SomeMicrosoftLibrary.dll
,并且由于我们已经移动了所有内容,所以我需要找到新的相对路径。 但我绝对讨厌尝试这样做(弄清楚我需要放入多少斜线和句号),因为它总是感觉像是一些偶然的科学。
是否有一些简单的方法(实用程序、脚本、代码片段)可以说“这是文件 A,这是文件 B,文件 B 相对于文件 A 的相对路径是什么?”
I'm in the midst of some refactoring some C# code and part of this is to redo some references, because we're redoing the folder structure entirely. What I'd like to do is just go into the .csproj or .sln file and modify the paths.
However some of the references have paths like
"../../../../../../ThirdParty/SomeMicrosoftLibrary/bin/Debug/SomeMicrosoftLibrary.dll
And since we've moved everything around I need to find the new relative path. But I absolutely hate trying to do this (figure out how many slashes and periods I need to put in) since it always feels like some hit or miss science.
Is there some easy way (utility, script, snippet of code) to say "here's file A, here's file B, what is the relative path of file B in relation to file A?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Ruby:
我很确定 Python 有类似的方法,尽管我手头没有。
With Ruby:
I'm pretty sure Python has a similar method, though I don't have it handy.
生成相对路径
它是 Java 语言,但可以轻松转换为 C#。
Generate a Relative Path
It's in Java, but easily translatable to C#.
我知道这已经过时了,但我一直在寻找这个问题的答案,所以这里有一个方法可以做到这一点,以防万一它可以帮助其他人在未来
I know this is old but I was looking for the answer to this so here's a method which does it, just in case it might help anyone else out in the future