Resolve absolute path from relative path and/or file name

前端 未结 14 1585
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 09:38

Is there a way in a Windows batch script to return an absolute path from a value containing a filename and/or relative path?

Given:

         


        
14条回答
  •  有刺的猬
    2020-11-27 09:59

    Without having to have another batch file to pass arguments to (and use the argument operators), you can use FOR /F:

    FOR /F %%i IN ("..\relativePath") DO echo absolute path: %%~fi
    

    where the i in %%~fi is the variable defined at /F %%i. eg. if you changed that to /F %%a then the last part would be %%~fa.

    To do the same thing right at the command prompt (and not in a batch file) replace %% with %...

提交回复
热议问题