开发者

How to get full path of a given path

开发者 https://www.devze.com 2022-12-25 17:44 出处:网络
I have a variable define as: set filePath=\".\\file.txt\" I\'开发者_如何学Cm writing a windows batch file. Need to convert the path stored in variable \'filePath\' to its fullpath (physical path).

I have a variable define as:

set filePath=".\file.txt"

I'开发者_如何学Cm writing a windows batch file. Need to convert the path stored in variable 'filePath' to its fullpath (physical path).

How can I get the full path of this path? Please help!


Since your question is tagged "command-line" I assume you want to do this in a Windows bat script. There you can expand a variable to the full path using the following syntax:

%~fI

where I is the name of the variable.

The following script will print you the full path to ".\file.txt":

set filePath=".\file.txt"
for %%F in (%filePath%) do set filePath=%%~fF
echo %filePath%

A full reference of available substitutions is contained in the description of the for command (http://technet.microsoft.com/en-us/library/bb490909.aspx).

0

精彩评论

暂无评论...
验证码 换一张
取 消