BAT to Check shortcut links work and allow quick editting?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JimmyTheDos
Posts: 3
Joined: 20 May 2018 20:28

BAT to Check shortcut links work and allow quick editting?

#1 Post by JimmyTheDos » 20 May 2018 22:00

Hi guys,

I have a way of creating multiple shortcuts in locations with many different targeted locations.
My biggest worry is that I change my folder structure, and then some of the shortcuts won't work any more.

Would anyone know if would be possible to create a BAT that asks for a location:

Code: Select all

@echo off
setlocal enabledelayedexpansion
cls
:input
set /p "input=1. Enter Source directory: "
if not exist "%input%" echo Invalid source: "%input%" enter valid path && goto :input

Finds any shortcuts within that directory and its sub-directories, and prints out the information in a CSV file (or maybe a txt file) with the following:
Column A: the Source's Directory location of the Shortcut.
Column B: the Targeted Directory Location the shortcut sends you too.
Column C: if the shortcut currently works or not.

Which i could edit and then with another BAT goes through the CSV and changes the Target locations to be the ones in the CSV file?


Any ideas would be great.
Thanks,
Jimmy 8)

MarioZac
Posts: 38
Joined: 16 May 2018 00:12

Re: BAT to Check shortcut links work and allow quick editting?

#2 Post by MarioZac » 22 May 2018 14:11

Shortcuts by definition work best when left on Desktop rather than in random folders. :D If you changed the directory structure, and a certain shortcut no longer works, use Everything to quickly find the original file or folder. Coding a batch to recursively look for, verify, find current if exist and unique, and change shortcut links on the entire disk sounds quite slow task, unless you show rational for such habit. The code snippet you posted above appears counterproductive as a method to do that, since the task can be fully automated.

If you want to refresh all shortcuts in a folder or disk, some code samples are posted in Editing multiple shortcut properties, Create a Windows shortcut through a batch file and such. Try to adapt and let us know if they work for you.

MarioZac
Posts: 38
Joined: 16 May 2018 00:12

Re: BAT to Check shortcut links work and allow quick editting?

#3 Post by MarioZac » 24 May 2018 06:58

This algorithm may be used recursively in your RefreshShortcuts.bat, assuming all shortcuts to original files are stored on C:\ drive, and you don't need to change current shortcut locations, but only refresh links to original files referenced in the shortcuts:

Code: Select all

- A. Using FOR-Files commands, find a shortcut file on disk C:\ with *.lnk extension
- find a text string in it - full path starting with C:\ and ending with any .??? extension
- check if the file_name.ext referenced in the string still exists at that path
- if exists - goto A , i.e. find next shortcut *.lnk , else find current path to the 1st file_name.ext on C:\*
- if the file exists replace the old path with current one in the *.lnk shortcut, else - delete the shortcut *.lnk
- goto A ... do above checks again for the next shortcut
- exit when all shortcuts are refreshed
Last edited by MarioZac on 24 May 2018 15:52, edited 1 time in total.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: BAT to Check shortcut links work and allow quick editting?

#4 Post by npocmaka_ » 24 May 2018 08:48

Try with shortcutjs.bat

May be something like:

Code: Select all

for %%a in "tokens=1* delims=:" %%a in ('shortcutjs.bat -examine "some.lnk"^|find /i "Target:"') do (
    if not exist "%%~fb"  echo target does not exist
    if not exist "%%~dp" echo target directory does not exist
    if exist  "%%~fb"  echo looks ok?
)

MarioZac
Posts: 38
Joined: 16 May 2018 00:12

Re: BAT to Check shortcut links work and allow quick editting?

#5 Post by MarioZac » 24 May 2018 09:05

@ npocmaka

Is it possible to add some description on Github what the shortcutjs.bat does? :)

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: BAT to Check shortcut links work and allow quick editting?

#6 Post by npocmaka_ » 24 May 2018 13:05

ok.

I thought that the help message is descriptive enough.

Post Reply