C# detect folder junctions in a path
Asked Answered
E

2

12

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.

Euphonize answered 9/2, 2011 at 10:32 Comment(0)
C
4

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

Cotsen answered 1/8, 2011 at 23:58 Comment(0)
J
2

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

Jaquez answered 9/2, 2011 at 13:8 Comment(1)
Have a look at this site too: pinvoke.net/default.aspx/kernel32.DeviceIoControl it will help you to get the signatures.Stegodon

© 2022 - 2024 — McMap. All rights reserved.