ElektroStudios / Easy-Link-File-Viewer

Desktop application for Windows to read, modify and write shortcut files (.lnk) with ease.
Apache License 2.0
125 stars 13 forks source link

[FEATURE] Recursive find on directory and replace link #13

Closed yerkog closed 2 months ago

yerkog commented 3 months ago

Is your feature request related to a problem? Please describe. The Easy-Link-File-Viewer is amazing, but recently I moved many files from my old PC to my new PC and now I have many link brokes.

Describe the solution you'd like Im really appreciate if in the new version included a new feature, like where can find all of link files from folder or directory and replace a pice of string.

Example: Replace "C:\Users\" -> "C:\Users\00-user2\"

Describe alternatives you've considered And also thinking in is possible change recursive the icon for all lin files or group selected.

Additional context Add any other context or screenshots about the feature request here.

ElektroStudios commented 2 months ago

Hi. I’m sorry but Easy Link File Viewer is not designed for batch processing operations. Implementing such features and making the necessary UI changes would require more time than what I can currently invest.

However, I can bring you a different solution to your issue. You can use the following Visual Basic Script file that will locate all shortcut (*.lnk) files inside the specified directory path and perform a string replacement in the TargetPathand WorkingDirectoryattributes for each one.:

Script.vbs

Option Explicit

Dim rootFolderPath, searchString, replaceString
Dim fso, shell, recursiveSearch

' Set your folder path, search string, replace string, 
' and whether to search recursively for *.lnk files.
rootFolderPath = "C:\Folder"
searchString = "C:\Users"
replaceString = "C:\Users\00-user2"
recursiveSearch = False

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")

If Not fso.FolderExists(rootFolderPath) Then
    WScript.Echo "The folder does not exist: " & rootFolderPath
    WScript.Quit
End If

ProcessFolder fso.GetFolder(rootFolderPath)

WScript.Echo "Operation completed."

Set shell = Nothing
Set fso = Nothing

Sub ProcessFolder(folder)
    Dim file, subFolder
    For Each file In folder.Files
        If LCase(fso.GetExtensionName(file.Name)) = "lnk" Then
            ProcessShortcut file
        End If
    Next

    If recursiveSearch Then
        For Each subFolder In folder.SubFolders
            ProcessFolder subFolder
        Next
    End If
End Sub

Sub ProcessShortcut(file)
    Dim shortcut, originalPath, workingDir, targetPathLower, searchLower, replaceLower

    On Error Resume Next 
    Set shortcut = shell.CreateShortcut(file.Path)

    originalPath = shortcut.TargetPath
    workingDir = shortcut.WorkingDirectory
    targetPathLower = LCase(originalPath)
    searchLower = LCase(searchString)
    replaceLower = replaceString

    If InStr(targetPathLower, searchLower) > 0 Then
        shortcut.TargetPath = Replace(originalPath, searchString, replaceLower, 1, -1, vbTextCompare)
        shortcut.WorkingDirectory = Replace(workingDir, searchString, replaceLower, 1, -1, vbTextCompare)
        shortcut.Save
        WScript.Echo "Updated shortcut: " & file.Path
    End If

    On Error GoTo 0
    Set shortcut = Nothing
End Sub 

You only need to save that code in Notepad as a plain text file named Script.vbs, and then double-click the Script.vbs file to run it.

But make sure to configure the script before using it, by writing the correct values in these fields:

' Set your folder path, search string, replace string, 
' and whether to search recursively for *.lnk files.
rootFolderPath = "C:\Folder"
searchString = "C:\Users"
replaceString = "C:\Users\00-user2"
recursiveSearch = False

Also, you can delete this line from the code if you feel that it is annoying to pop-up this message on screen for each link file processed:

WScript.Echo "Updated shortcut: " & file.Path

Feel free to reopen this issue if you have any further questions.

Thanks for your feedback!.