Search for links by target

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Search for links by target

Post 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?

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

Re: Search for links by target

Post by highend »

How where these links created? Context menu on a folder - Create shortcut?
One of my scripts helped you out? Please donate via Paypal

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post 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.

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

Re: Search for links by target

Post 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);
        }
    }
One of my scripts helped you out? Please donate via Paypal

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post by igurin »

So this will actually retarget the links, right? This wasn't clear to me from your post.

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

Re: Search for links by target

Post 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...
One of my scripts helped you out? Please donate via Paypal

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post 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).

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

Re: Search for links by target

Post by highend »

Then use the Special Property - Shortcut Target column...
One of my scripts helped you out? Please donate via Paypal

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post 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.

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Search for links by target

Post 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.

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post by igurin »

Huh? I right-clicked on the column header, and I see a long list of available columns, but no "Select Special Property".

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

Re: Search for links by target

Post by highend »

In that context menu you choose "Add Column"
Afterwards right click the new "(Undefined)" column header and choose "Select Special Property..."
One of my scripts helped you out? Please donate via Paypal

igurin
Posts: 16
Joined: 10 Dec 2019 20:11

Re: Search for links by target

Post by igurin »

Aha. Got it! Thanks!

Post Reply