Resolve absolute path from relative path and/or file name

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

    You can also use batch functions for this:

    @echo off
    setlocal 
    
    goto MAIN
    ::-----------------------------------------------
    :: "%~f2" get abs path of %~2. 
    ::"%~fs2" get abs path with short names of %~2.
    :setAbsPath
      setlocal
      set __absPath=%~f2
      endlocal && set %1=%__absPath%
      goto :eof
    ::-----------------------------------------------
    
    :MAIN
    call :setAbsPath ABS_PATH ..\
    echo %ABS_PATH%
    
    endlocal
    

提交回复
热议问题