Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 583 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the absolute path of file in batch script

#1
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.
Reply

#2
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
Reply

#3
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.
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through