Resolve absolute path from relative path and/or file name

前端 未结 14 1797
被撕碎了的回忆
被撕碎了的回忆 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:58

    PowerShell is pretty common these days so I use it often as a quick way to invoke C# since that has functions for pretty much everything:

    @echo off
    set pathToResolve=%~dp0\..\SomeFile.txt
    for /f "delims=" %%a in ('powershell -Command "[System.IO.Path]::GetFullPath( '%projectDirMc%' )"') do @set resolvedPath=%%a
    
    echo Resolved path: %resolvedPath%
    

    It's a bit slow, but the functionality gained is hard to beat unless without resorting to an actual scripting language.

提交回复
热议问题