Page 1 of 1

Search for links by target

Posted: 20 Jan 2020 22:44
by igurin
Use case: I want to move a folder (call it X), and I want to retarget any links that point to it.

Tried approach 1: use the search tool to find links (*.lnk) targeting X. The search tool has no such feature. :(

Tried approach 2: find all *.lnk and add a column to the search results tab to show the link targets. Column doesn't exist. :(

Tried approach 3: find all *.lnk and grab a report of the metadata. The metadata report that I want seems to only work for folders, not for search results. :(

Tried approach 4: find all *.lnk, move to a paper folder, and then grab a report of the metadata. Still doesn't work. :(

Best option that I've found: find all *.lnk, open up the "Meta" tab in the bottom pane (which shows link targets) and scan through one file at a time. This really sucks, though, because I'm searching on the network and XYPlorer occasionally freezes to wait for a server to respond. :?

There has to be a better way to do this, right?

Re: Search for links by target

Posted: 20 Jan 2020 22:49
by highend
How where these links created? Context menu on a folder - Create shortcut?

Re: Search for links by target

Posted: 20 Jan 2020 23:12
by igurin
Probably either that or right-drag and "create shortcut here." I'm willing to assume for the moment that they're all *.lnk files, if that's what you're getting at. There shouldn't be any hard links or other "power user" features.

Re: Search for links by target

Posted: 20 Jan 2020 23:32
by highend
Tried approach 2: find all *.lnk and add a column to the search results tab to show the link targets. Column doesn't exist
You could create such a column btw...
Special property: Shortcut Target

Here is an all-in-one solution:

Go into the folder that will contain any .lnk files (subfolders are recursively scanned from here onwards, too).
Start the script.
Select the folder that is the new one.
Enter the old folder name with full path (the one that the existing .lnk file still links to!).

Code: Select all

$newDst = inputfolder(, "Select the new destination folder...");
    $oldDst = input("Enter old folder (before the move)", , $newDst, , , 600);
    end ($newDst LikeI $oldDst), "New and old folders are the SAME, aborted!";

    $links = quicksearch("*.lnk /excl=\System Volume Information\|\$RECYCLE.BIN\");
    setting "BackgroundFileOps", 0;
    foreach($link, $links, <crlf>, "e") {
        $target = property("#LinkTarget", $link);
        if ($target LikeI $oldDst) {
            $path = gpc($link, "path");
            $name = regexreplace(gpc($newDst, "file"), "\.lnk$") . ".lnk";
            delete 0, 0, $link;
            new("$path\$name", "link", $newDst);
        }
    }

Re: Search for links by target

Posted: 21 Jan 2020 02:37
by igurin
So this will actually retarget the links, right? This wasn't clear to me from your post.

Re: Search for links by target

Posted: 21 Jan 2020 08:22
by highend
No, it will delete the old ones and create new ones instead. Modifying would be possible but not without e.g. some additional VBScript...

Re: Search for links by target

Posted: 21 Jan 2020 18:57
by igurin
OK, that's not exactly what I want.
  1. I'm okay with changing the links manually (I expect there to be fewer than a dozen).
  2. Using the same $newDst for everything won't work, because the links may point to subfolders or files within folder X. :bug:
  3. I also want to see the individual changes, preferably before I make them (see also #1).

Re: Search for links by target

Posted: 21 Jan 2020 19:12
by highend
Then use the Special Property - Shortcut Target column...

Re: Search for links by target

Posted: 22 Jan 2020 01:27
by igurin
That's what I was looking for, but I don't see it. I opened the Custom Columns setup, but those are mostly for photos and audio files.

Re: Search for links by target

Posted: 22 Jan 2020 02:05
by nas8e9
igurin wrote: 22 Jan 2020 01:27 That's what I was looking for, but I don't see it. I opened the Custom Columns setup, but those are mostly for photos and audio files.
You need the "Select Special Property" menu item when right-clicking on the column header.

Re: Search for links by target

Posted: 23 Jan 2020 19:38
by igurin
Huh? I right-clicked on the column header, and I see a long list of available columns, but no "Select Special Property".

Re: Search for links by target

Posted: 23 Jan 2020 20:14
by highend
In that context menu you choose "Add Column"
Afterwards right click the new "(Undefined)" column header and choose "Select Special Property..."

Re: Search for links by target

Posted: 25 Jan 2020 00:58
by igurin
Aha. Got it! Thanks!