Windows 7 Script (or other mechanism) to copy shortcut target to a new folder

goshenBleeping

Senior Member
Joined
May 23, 2013
I am looking for a Windows 7 script (perhaps in vbs) or another mechanism that will copy the target of a shortcut to a new folder.


If the shortcut points to a single file, copy the file to the new folder
If the shortcut points to a folder, copy that folder to the new folder
If the shortcut points to a folder & the folder has children, copy that folder & all of its children to the new folder


Thank you.
 
@echo OFF
SET Shortcut=%~1
ECHO SET WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
ECHO SET Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
ECHO wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
SET vbscript=cscript //nologo DecodeShortCut.vbs
for /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
DEL DecodeShortCut.vbs
ECHO Shortcut: %shortcut%
ECHO Target: %target%

I forget where I got this from, but it has to date been the easiest way to do this from command prompt, if you don't want it to be a batch file and prefer vbs, I'm sure you can parse the vbs which is just piped to a temp file and deleted afterwards to get the desired result.

Works fine on shortcuts (.lnk files) to files as well as folders.
 
Oh and as far as copying it depending if its a file/folder, look into xcopy or robocopy and its options.
 
@echo OFF
SET Shortcut=%~1
ECHO SET WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
ECHO SET Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
ECHO wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
SET vbscript=cscript //nologo DecodeShortCut.vbs
for /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
DEL DecodeShortCut.vbs
ECHO Shortcut: %shortcut%
ECHO Target: %target%

I forget where I got this from, but it has to date been the easiest way to do this from command prompt, if you don't want it to be a batch file and prefer vbs, I'm sure you can parse the vbs which is just piped to a temp file and deleted afterwards to get the desired result.

Works fine on shortcuts (.lnk files) to files as well as folders.
Thanks
 
Back
Top Bottom