Linked files with hard link

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Linked files with hard link

Post by zakoul »

There is a utility FindLinks from sysinternals that displays all files associated with a hard link.
Is there such a possibility in the XYplorer? So that when you select a file with a hard link, all associated files are displayed.

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

Re: Linked files with hard link

Post by highend »

No, because fsutil would need to be invoked to get that info

Code: Select all

    $results    = trim(runret("""fsutil"" hardlink list ""<curitem>""", , 65001), <crlf>);
    $cntResults = gettoken($results, "count", <crlf>);
    if ($cntResults >= 2) {
        $drive     = gpc(<curitem>, "drive") . ":";
        $hardlinks = gettoken($results, $cntResults - 1, <crlf>, , 1);
        $hardlinks = regexreplace($hardlinks, "^(.)", $drive . "$1");

        $header = "Hardlink(s) to <curitem>";
        $output = $header . <crlf> . strrepeat("=", strlen($header)) . <crlf> . $hardlinks;
        text $output;
    }
You can see where a file points to but that requires hovering over a hardlink, not its source...
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

Thank you. Works.
Last edited by zakoul on 21 Jul 2021 11:23, edited 1 time in total.

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

Re: Linked files with hard link

Post by highend »

If there are no hardlinks pointing to the selected file, no, nothing will happen
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

The last link does not display
Image

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

Re: Linked files with hard link

Post by highend »

Yeah, fsutil is a bit weird sometimes (at one time the source file is listed first, on other occasions as the last entry)

This should avoid it:

Code: Select all

    $results    = runret("""fsutil"" hardlink list ""<curitem>""", , 65001);
    $escaped    = regexreplace(substr(<curitem>, 2), "([\\.+(){\[^$])", "\$1");
    $results    = trim(regexreplace($results, "^$escaped(\r?\n|$)"), <crlf>);
    $cntResults = gettoken($results, "count", <crlf>);
    if ($cntResults >= 1) {
        $drive   = gpc(<curitem>, "drive") . ":";
        $results = regexreplace($results, "^(.)", $drive . "$1");
        $header  = "Hardlink(s) to " . quote(<curitem>);
        $output  = $header . <crlf> . strrepeat("=", strlen($header)) . <crlf> . $results;
        text $output;
    }
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

Is it possible to draw a conclusion in a non-modal window? Or tear it off right in your notepad.exe.
When "text $output" is displayed, the explorer is not available.

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

Re: Linked files with hard link

Post by highend »

Then use something like

Code: Select all

        writefile("%TEMP%\~fsutil.txt", $output, , "utf8");
        run """notepad.exe"" ""%TEMP%\~fsutil.txt""";
instead of

Code: Select all

text $output;
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

Thank you.

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

Last moment. If nothing is selected (click on an empty space), then the window is displayed. Can I fix this, if not difficult?
Image

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

Re: Linked files with hard link

Post by highend »

Code: Select all

if (!<get CountSelected>) { end true; }
?
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

:tup:

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

highend, Found a problem with symbols.
Image

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

Re: Linked files with hard link

Post by highend »

Try to replace

Code: Select all

    $results    = runret("""fsutil"" hardlink list ""<curitem>""", , 65001);
with

Code: Select all

    $cmd        = <<<>>>
cmd /c @chcp 65001 >NUL 2>NUL & fsutil hardlink list "<curitem>"
    >>>;
    $results    = runret("$cmd", , 65001);
One of my scripts helped you out? Please donate via Paypal

zakoul
Posts: 130
Joined: 11 Dec 2019 10:44

Re: Linked files with hard link

Post by zakoul »

Can't get information from folder \Systems32\
Image

Post Reply