Possible to sort shortcuts by target path?

Page 1 of 2 12 LastLast

  1. Posts : 213
    Windows10
       #1

    Possible to sort shortcuts by target path?


    Hello -
    I have a folder on my desktop where I have approx 100 shortcuts to various portable installs, other locations,
    etc,etc.
    In Windows Explorer I put the items in details view, but I'm unable to find a details column that contains this
    particular item.

    Any ideas appreciated
      My Computer


  2. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, here's a folder of shortcuts with the shortcut paths and their target paths in two columns in a spreadsheet.

    Note: this will not help you sort the actual shortcuts! I don't know of a way to do that in file explorer, so this is probably just an interesting toy.

    Only if you could add the target path to a field you could display in a column in file explorer would you then have a column where the target was visible in file explorer.

    (The output is a CSV file which I've opened in a spreadsheet, so you can do with that what you wish).

    Once you have them in that format you can search or organise as you will.
    Possible to sort shortcuts by target path?-1.jpg

    Here I've launched a Powershell script with Powershell open at the folder of interest.
    That creates a CSV file on your desktop.

    $SourceDir = Split-Path -Path .

    $ShellThing = New-Object -ComObject 'WScript.Shell'
    $AllLinks = (Get-ChildItem -Path $SourceDir -Recurse -File -Filter '*.lnk' -ErrorAction 'SilentlyContinue').Fullname

    $Results = foreach ($Link in $AllLinks)
    {
    [PSCustomObject]@{
    Lnk_FileName = $Link
    Lnk_Target = $ShellThing.CreateShortcut($Link).TargetPath
    }
    }

    $Results | Export-Csv -Path ~\Desktop\Output.csv -NoTypeInformation


    Borrowed and very slightly adapted from here:
    reddit Powershell thread
      My Computers


  3. Posts : 213
    Windows10
    Thread Starter
       #3

    Thank you dalchina, this will help
      My Computer


  4. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    The really tricky thing is making any use of that as I've mentioned, so you can actually sort the shortcuts themselves.

    I don't know of a way to use Windows search to do that, for example.

    By comparison XYplorer has its own commenting system, so if the target path were copied as a comment, you would have a Comments column you could organise (and XYplorer provides scripting too FWIW).
    Possible to sort shortcuts by target path?-1.jpg
      My Computers


  5. Posts : 213
    Windows10
    Thread Starter
       #5

    That's intersting, wrote a response on my phone, submitted it, attempted to edit, accidentally deleted it.
    Take 2
    If I can sort the results in the list, that's enough. Due to some poor organization on my part
    I have some shortcuts executing portable installs from locations where they really shouldn't be.
    I want to move them to somewhere more appropriate leaving me free to archive the rest of the folder(s) to DVD.
    Thanks for the extra info
      My Computer


  6. Posts : 745
    Windows 10/11
       #6

    davexnet said:
    wrote a response on my phone, submitted it, attempted to edit, accidentally deleted it.
    You didn't accidentally delete it. That's a site bug. TenForums is not good on mobile. Elevenforums, OTH, is great on mobile.
      My Computer


  7. Posts : 1,223
    W10-Pro 22H2
       #7

    I wondered whether a shortcut could have a comment - and it can - but its called a 'description' in vbs, so took a bit of finding. This page was the main help: Shortcut - VBScript - SS64.com

    The following vb script will set the descriptions to the target path - you will have to copy the code, and paste into a file with the extension VBS (I assume vbs will run on your PC, not sure if it takes any setting up).
    Code:
    '18/12/23 MNG try to set description/comment on shortcut
    'Drag folder and drop on script to pass folder name
    
    wscript.echo "args(0):" & wscript.arguments(0)
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(wscript.arguments(0))
    set objFiles = objFolder.files
    for each filnam in objFiles
    	if filnam.type = "Shortcut" then
    		wscript.echo filnam
    		Set lnk = WshShell.CreateShortcut(filnam)
    		lnk.description = lnk.targetpath
    		'lnk.description = "cleared"
    		lnk.save()
    	end if
    next
    To set (or clear) the comments for all shortcuts in a folder, simply drag and drop the folder onto the script. I am sure it can blow up in many ways I have not yet tested! hth, Martin
      My Computer


  8. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #8

    Interesting outside the box thinking - here's an example of the result to show how that appears:
    Possible to sort shortcuts by target path?-1.jpg

    - the exception is the URL shortcuts.
    Last edited by dalchina; 18 Dec 2023 at 08:01.
      My Computers


  9. Posts : 1,223
    W10-Pro 22H2
       #9

    dalchina said:
    - the exception is the URL shortcuts.
    Yes, I didn't try to check for URL scs - I don't know if the FSO recognises them. Glad to see it worked for someone else!

    Update: URL Files cannot have descriptions - they may have something else, though.
      My Computer


  10. Posts : 213
    Windows10
    Thread Starter
       #10

    mngerhold said:
    Yes, I didn't try to check for URL scs - I don't know if the FSO recognises them. Glad to see it worked for someone else!

    Update: URL Files cannot have descriptions - they may have something else, though.
    (safely at my desktop now)
    Thanks for this vbs code. Had to press enter for every shortcut in the folder, but it works well
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 15:50.
Find Us




Windows 10 Forums