Windows 7 Need a script to remove "- shortcut" from all shortcuts on computer

larryvc

Extraordinary Member
Joined
Mar 23, 2012
Messages
2
Script to remove "- shortcut" from all shortcuts on computer

Hi,

I finally got around to turning off the "- shortcut" that is appended to the shortcut name by editing the registry on a friends computer. He has way to many shortcuts in my opinion.

Does anyone have a script, or would someone like to write a script, that will rename all the shortcuts on a computer that have "ShortcutName - shortcut" to "ShortcutName".

I can write most of the script myself. The code I need help with is the parsing of the filename. I have not started to write the code yet, just trying to get some ideas as I thought this could be useful for other file renaming tasks as well.

I have not done any scripting for many years and any help would be appreciated.

Thanks
 


Last edited:
Solution
To create a script that removes "- shortcut" from all the shortcut names on a computer, you can utilize a scripting language like PowerShell. Here is an outline of the steps your script would need to perform:
  1. Get a list of all shortcuts on the computer.
  2. For each shortcut:
    • Check if the name contains "- shortcut".
    • If it does, rename the shortcut by removing "- shortcut" from the name. Below is a sample PowerShell script that achieves this:
      Code:
      # Get all shortcuts on the computer $shortcuts = Get-ChildItem -Path "$env:USERPROFILE\Desktop" -Filter "*.lnk" -Recurse foreach ($shortcut in $shortcuts) { $shortcutName = $shortcut.BaseName $newName = $shortcutName -replace " - shortcut", "" if ($shortcutName -ne $newName) {...
To create a script that removes "- shortcut" from all the shortcut names on a computer, you can utilize a scripting language like PowerShell. Here is an outline of the steps your script would need to perform:
  1. Get a list of all shortcuts on the computer.
  2. For each shortcut:
    • Check if the name contains "- shortcut".
    • If it does, rename the shortcut by removing "- shortcut" from the name. Below is a sample PowerShell script that achieves this:
      Code:
      # Get all shortcuts on the computer $shortcuts = Get-ChildItem -Path "$env:USERPROFILE\Desktop" -Filter "*.lnk" -Recurse foreach ($shortcut in $shortcuts) { $shortcutName = $shortcut.BaseName $newName = $shortcutName -replace " - shortcut", "" if ($shortcutName -ne $newName) { Rename-Item -Path $shortcut.FullName -NewName "$newName.lnk" } }
      Instructions on using the script:
    []Copy the script above into a PowerShell script file (e.g., RemoveShortcutSuffix.ps1). []Run PowerShell as an administrator.
  3. Execute the script by entering the file path where you saved it. Please ensure to test the script on a small set of shortcuts first to verify that it works as expected. Let me know if you need any further assistance with this script!
 


Solution
Back
Top