Reputation: 20464
This is my problem:
1º - I have a original folder with subfolders, full of mp3 files
2º - I have a copy of the original folder.
3º - I've "converted" all the "mp3" files of the copied folder into "lnk" files (With NirCMD CLI tool) maintaining the folders structure.
Now I need to check periodically if the target of every .lnk stills alive or is truncated, because i'm in maintenance everyday with the original folder, moving the files or doing something...
I need something like this:
Echo: Corrupted links:
For /F "tokens=*" %%# in ('Dir /B /AD') do (
Pushd ".\%%#"
For /F "tokens=*" %%# in ('Dir /B "*.lnk"') do (
(SHORTCUT_CHECK_PROGRAM_OR_FUNCTION_OR_SOMETHING.EXE) "%%#"
IF NOT %ErrorLevel% EQU 0 (Echo: Target doesn't exist: "%%#")
)
POPD
)
I've checked the parameters of:
mediainfo.exe
nircmd.exe shortcut
shortcut.exe
Vbscripts functions to create shortcuts (i can't find one vbs only for check the target)
But i can't find a method to use someone for give me info about the target of a shortcut.
Please, help
PD: I agree too a solution from 3rd party apps :)
PD2: The target of ALL .lnks have this especial latin char "ú" (I can convert the char if a solution is for Batch, Other way i don't know how to set the char right)
Thankyou!
EDIT:
Narayanan i don't know how to use VBA but i give you points for your help, thankyou.
I've remembered that I made a tempfile cleaner in batch years ago and I had the same problem to check taskbar shortcuts and delete them.
I've solved the problem but I did not remember xD
Take this if is helpful for someone:
(the vbs sends a errorlevel code)
PD: The code it's in spanish, but everyone can understand it :)
:Comprobar_accesos_directos_rotos.vbs
::Check invalid shortcuts target.vbs
:::::::::::::::::::::::::::::::::::::
echo set objshell = createobject("wscript.shell")>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo set objlink = objshell.createshortcut(wscript.arguments(0))>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo set objfso = createobject("scripting.filesystemobject")>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo if objfso.fileexists(objlink.targetpath) then>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo wscript.quit(0)>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo else>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo wscript.quit(1)>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
echo end if>>"%TEMP%\Comprobar_accesos_directos_rotos.vbs"
For /F "Tokens=*" %%a in ('dir /B /S "%appdata%\Microsoft\Windows\Start Menu\Programs\*.lnk"') do (
Set archivo="%%a"
call :comprobar
)
Goto :END
:Comprobar
::::::::::
"%TEMP%\Comprobar_accesos_directos_rotos.vbs" %archivo%
If %errorlevel% EQU 0 (
goto:eof
) ELSE (
Del /Q /F %archivo% >nul 2>&1
goto:eof
)
:END
pause
bye
Upvotes: 0
Views: 2567
Reputation: 3920
It appears to be a big pain to do that as no ready made solutions are available to my limited knowledge.
However, you can create a small executable which will return an errorlevel if the link's target is missing. This web page explains how to create such a program.
Upvotes: 1