MjWh Posted October 18, 2018 Posted October 18, 2018 Noob Alert Is this the correct forum for help with Batch files running under windows ?? thanks M
MjWh Posted October 18, 2018 Author Posted October 18, 2018 Thanks. I have a batch file that calls a Java script to process a data file .. java -jar RefineReqIF-9.2.1.jar -input .\datafile.dat -output .\processed_data.dat I need to have a line above this that will copy a file from somewhere else to the current folder and rename it (no problem with that) except that the somewhere else is a shortcut to a windows folder. I have found lots of referenceson using batch commends to run programs from their shortcuts but not how to use a shortcut in a path. Copy c:\temp\data.dat .\newfile.dat I need to replace c:\temp with my shortcut sources.lnk TIA Mark
djm968 Posted October 18, 2018 Posted October 18, 2018 You can extract the path from a shortcut link using a wmic query, see script below. @echo off setlocal rem // ensure user supplied a filename with a .lnk extension if /i "%~x1" neq ".lnk" ( echo usage: %~nx0 shortcut.lnk goto :EOF ) rem // set filename to the fully qualified path + filename set "filename=%~f1" rem // get target for /f "delims=" %%I in ( 'wmic path win32_shortcutfile where "name='%filename:\=\\%'" get target /value' ) do for /f "delims=" %%# in ("%%~I") do set "%%~#" rem // preserve ampersands setlocal enabledelayedexpansion echo(!target!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now