Page 1 of 1

Managing junctions / symlinks

Posted: 22 Mar 2019 23:37
by tim
Hi. I plan to have sort of system consisting of many junctions. Junction is bound to target path, which could be sometime changed. So, the question – is there any way in XY to:
  1. Search junctions (or symlinks) in file system by target path.
  2. Replace target path on found junctions (or just delete broken junction and create new one with updated target in the same place).
Thanks!

Re: Managing junctions / symlinks

Posted: 23 Mar 2019 00:48
by highend
Only by scripting

Re: Managing junctions / symlinks

Posted: 23 Mar 2019 16:37
by tim
highend wrote: 23 Mar 2019 00:48 Only by scripting
Okay, I guessed. Could you please point where in Scripting API I can read junction's target path value? Maybe there is some junction object that has desired property. Or global function. I haven't found yet. Thank you!

Re: Managing junctions / symlinks

Posted: 23 Mar 2019 18:51
by highend

Code: Select all

property()
can do it. Iirc the property itself is called #JunctionTarget

Re: Managing junctions / symlinks

Posted: 25 Mar 2019 11:21
by highend
E.g.:

Code: Select all

    // The destination path that a junction must point to (or a subfolder of it)
    $dstForJunction = "D:\";

    // Get all folders recursively from the current folder and from them only the junctions...
    $folders   = quicksearch("/d", , , "sm");
    $junctions = regexmatches($folders, "^.+\|...D...J", <crlf>);
    $junctions = regexreplace($junctions, "^(.+?)\|(.*?(?=\r?\n|$))", "$1");
    if !($junctions) { status "No junctions found, aborted!", "8B4513", "stop"; end true; }

    $log = "";
    foreach($junction, $junctions, <crlf>, "e") {
        $target = property("#JunctionTarget", $junction);
        if (strpos($target, $dstForJunction) != -1) {
            $log .= $junction . " -> " . $target . <crlf>;
            // Do your own stuff, write .bat file entries / or repair / delete
            // with XY scripting (but only if XY is running elevated!)
        }
    }
    if ($log) { text $log; }