Solved

Batch editing shortcut targets

Posted on 2013-01-04
10
1,105 Views
Last Modified: 2013-01-05
Running Windows 7 Professional SP-1, I have just converted over a thousand .wps files to .docx.   However, now there are hundreds of shorcuts, in myriad folders, which point to non-existent .wps files.  I would like to batch edit these links, to point them to the new .docx files.  The application which I usually rely upon, Shortcut Doctor, is not performing, for some reason.  It finds all the references to .wps in shortcut links, but will not change them to .docx (it doesn't find them again, during the Replace process, although it found them during the Search process).  Is there an application or a script which I can use, which will locate all these shortcuts and update them?
0
Comment
Question by:ddantes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 9

Accepted Solution

by:
shorvath earned 375 total points
ID: 38746005
try this:

'References:
'Microsoft Shell Controls And Automation
'Microsoft Scripting Runtime
'Windows Script Host Object Model


Dim oWsShell As New WshShell
Dim oShell  As Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oFolderItems As Shell32.FolderItems
Dim FSO As New FileSystemObject
Dim oShtCut As Object
Dim LinkPath As String

LinkPath = "C:\Temp"  'set to your links path

Set oShell = New Shell32.Shell
Set oFolder = oShell.NameSpace(LinkPath)
Set oFolderItems = oFolder.Items

For Each Item In oFolderItems
   If Item.IsLink = True Then
      Set oShtCut = oWsShell.CreateShortcut(LinkPath & "\" & Item.Name & ".lnk")
      If InStr(1, oShtCut.TargetPath, ".wps") > 0 Then
         oShtCut.TargetPath = Replace(oShtCut.TargetPath, ".wps", ".docx")
         oShtCut.Save
         FSO.MoveFile oShtCut.FullName, Replace(oShtCut.FullName, ".wps", ".docx")
      End If
   End If
Next

Set oShtCut = Nothing
Set oFolderItems = Nothing
Set oFolder = Nothing
Set oShell = Nothing
Set FSO = Nothing

Open in new window

0
 

Author Comment

by:ddantes
ID: 38746032
Thank you for that script.  Sorry for my ignorance, but how should I apply that?  In other words, what is needed in order to execute that?
0
 

Author Comment

by:ddantes
ID: 38746108
I think I found out how to run the script.  I get this error:
(7, 14) Microsoft VBScript compilation error: Expected end of statement
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 125 total points
ID: 38746539
Hi, the code Shorvath posted is VBA, not pure VBScript.  You appear to have created a VBS file to run the code, hence the error.

To run the code, launch Excel, and open the code editor (ALT + F11). Insert a new module, and paste the code into it, then add the references noted at the top via Tool --> References, and run the code.

Regards,

Rob.
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 38746820
Are these LNK files that you need to update?

Do you want the script to only process the files in a specified folder, or do you want it to search all subfolders as well?

Do you want it to verify that the target file (with the WPS extension) exists before the change, and only update the link if true?

~bp
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38746906
Sorry, but I saw this question under the VB Classic Group.   I did run this with VB6 and it worked.  It did rename the Target File in the .lnk file, and then renamed the Shortcut itself to reflect the new file name. I did assume that the Target path of the file and the file name has NOT changed, only the extension. ( .wps to .docx)  I will be back at work next week to test it under Windows 7, VB script, but the logic is sound and working.
0
 

Author Comment

by:ddantes
ID: 38747534
Rob:  Thank you for your instructions.  I pasted the code into a new Excel module, added the Refererences, but I don't know how to run it.  When I select "Run", it asks for a macro name.
0
 

Author Comment

by:ddantes
ID: 38747642
Never mind, I worked it out.  Thank you for the code and implementation instructions -- works like a charm!
0
 

Author Comment

by:ddantes
ID: 38747655
(Deleted)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question