I am using batch script to invoke java application. Java app takes an absolute file path as an argument.
I need my batch script to be invoked with the relative or absolute path of the file as an argument and then to pass the absolute path of the file for java execution. Example:
Running script myscript
from location c:/folderA
myscript folderB/file.txt
myscript c:/folderA/folderB/file.txt
should be able to get full absolute path c:/folderA/folderB/file.txt
in both cases.
How do I do that?
Just to be as much concrete as possible: I need only BATCH SCRIPT code to retrieve absolute file path string after passing either relative or absolute path to ti as an argument. Not the actual part when I invoke the java app with it.
You can use %~dpnx1
, which expands to the drive, path, name and extension of the first argument. Don't forget to quote the name when passing it to another command, though.
Absolute path in "for...do" statement is %~f{variable_letter}
.
Absolute path in procedure call for argument %1
is %~f1
or %~dpnx1
but for an environment variable no simple solution.
Workaround is create procedure with set statement e.g (for Windows XP and newer):
@echo off
cd C:\Program Files\Microsoft Games
call :getabsolute "Purble Place\PurblePlace.exe"
echo %absolute%
call :getabsolute "Purble Place"
echo %absolute%
pause
goto :eof
:getabsolute
set absolute=%~f1
goto :eof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With