Managing junctions / symlinks

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
tim
Posts: 54
Joined: 19 Apr 2014 03:49

Managing junctions / symlinks

Post by tim » 22 Mar 2019 23:37

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!

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Managing junctions / symlinks

Post by highend » 23 Mar 2019 00:48

Only by scripting
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

tim
Posts: 54
Joined: 19 Apr 2014 03:49

Re: Managing junctions / symlinks

Post by tim » 23 Mar 2019 16:37

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!

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Managing junctions / symlinks

Post by highend » 23 Mar 2019 18:51

Code: Select all

property()
can do it. Iirc the property itself is called #JunctionTarget
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Managing junctions / symlinks

Post by highend » 25 Mar 2019 11:21

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; }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

Post Reply