C# 检测路径中的文件夹连接
我想快速检查完整路径中是否使用了连接点。我已经有一个函数来测试像 IsJunction()
这样的文件夹,但也许还有其他解决方案,不在每个子文件夹上调用 IsJunction()
。
因此,我正在寻找像 HasJunctionsInPath(string path)
这样的函数,而不测试路径的每个文件夹。
有什么东西可以做到这一点吗?
编辑:
或者更好...
是否可以解析路径中的所有连接点以获取文件或文件夹的真实位置?这将更好地解决我的问题,我仍然可以将结果与原始路径进行比较,以实现 bool HasJunctionsInPath(string path) 函数。
I want to make a quick check if in a complete path a Junction point is used. I already have a function to test a folder like IsJunction()
but maybe there is an other solution to not call IsJunction()
on every subfolder.
So I'm looking for a function like HasJunctionsInPath(string path)
without testing each folder of the path.
Is there something which can do this?
Edit:
Or better...
Is it possible to resolve all junctions in a path to get the real location of a file or folder? This would be even better solve my problem and I still can compare the result with the original path to implement a bool HasJunctionsInPath(string path)
function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看杰夫·布朗的解决方案。
他在静态类中实现了您的功能,这似乎工作得很好。
http://www.codeproject.com/KB/files/JunctionPointsNet.aspx
Look at the solution of Jeff Brown.
He implemented your features in a static class, that seems to just work fine.
http://www.codeproject.com/KB/files/JunctionPointsNet.aspx
据我所知,c# 中没有开箱即用的实现来直接处理连接/重分析点。
所以你必须与 kernel32.dll 进行一些互操作。这有点棘手,但你可以找到样本。
您将需要 CreateFile() & DeviceIoControl() 调用。
这是一个很好的开始示例:
http://www.codeproject.com/KB/vista/ReparsePointID.aspx ?display=Print
有用的 msdn 链接:
http ://msdn.microsoft.com/en-us/library/cc232007%28PROT.13%29.aspx
http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us /library/aa363216%28v=vs.85%29.aspx
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/7acd564f-0e9f-4295-8609-916af6675f0a
As far as I know there's no out of the box implementation in c# to handle junctions / reparse points directly.
So you have to do some interop with kernel32.dll. This is a bit tricky, but you find samples.
You'll need the CreateFile() & DeviceIoControl() calls.
Here is a good sample to start:
http://www.codeproject.com/KB/vista/ReparsePointID.aspx?display=Print
useful msdn links:
http://msdn.microsoft.com/en-us/library/cc232007%28PROT.13%29.aspx
http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/aa363216%28v=vs.85%29.aspx
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/7acd564f-0e9f-4295-8609-916af6675f0a