Resolve absolute path from relative path and/or file name

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

    I came across a similar need this morning: how to convert a relative path into an absolute path inside a Windows command script.

    The following did the trick:

    @echo off
    
    set REL_PATH=..\..\
    set ABS_PATH=
    
    rem // Save current directory and change to target directory
    pushd %REL_PATH%
    
    rem // Save value of CD variable (current directory)
    set ABS_PATH=%CD%
    
    rem // Restore original directory
    popd
    
    echo Relative path: %REL_PATH%
    echo Maps to path: %ABS_PATH%
    
    0 讨论(0)
  • 2020-11-27 10:20

    Files See all other answers

    Directories

    With .. being your relative path, and assuming you are currently in D:\Projects\EditorProject:

    cd .. & cd & cd EditorProject (the relative path)

    returns absolute path e.g.

    D:\Projects

    0 讨论(0)
提交回复
热议问题