How to get the path of the batch script in Windows?

前端 未结 8 1333

I know that %0 contains the full path of the batch script, e.g. c:\\path\\to\\my\\file\\abc.bat

I would path to be equal to

8条回答
  •  没有蜡笔的小新
    2020-12-04 05:26

    I am working on a Windows 7 machine and I have ended up using the lines below to get the absolute folder path for my bash script.

    I got to this solution after looking at http://www.linuxjournal.com/content/bash-parameter-expansion.

    #Get the full aboslute filename.
    filename=$0
    #Remove everything after \. An extra \ seems to be necessary to escape something...
    folder="${filename%\\*}"
    #Echo...
    echo $filename
    echo $folder
    

提交回复
热议问题