The syntax %~f1 modifies a parameter representing a filename into its fully qualified path. Is there a way to get that functionality for variables defined within the batch script, and not just for parameter values?
For example, if a user provides a command line parameter "test.txt", the following script works:
echo Qualified filename: %~f1
But if I try to do the same thing with a variable instead of a parameter, how can I get the same functionality? This attempt is invalid syntax and does not work:
set unqualifiedFilename="test.txt"
echo Qualified filename: %~funqualifiedFilename
The simplest way I can think of is to just use a FOR
command.
Sample batch script:
@echo off
setlocal
set FileName=test.cmd
for %%i in (%FileName%) do set FullPath=%%~fi
echo Original param was '%FileName%'; full path is '%FullPath%'
Sample output:
Original param was 'test.cmd'; full path is 'C:\test.cmd'
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