Search code examples
windowsbatch-filedirectoryparent

How to get windows batch's parent folder


I'm writing a batch file, I need to get the parent folder of this bat file. Is it possibile? NB I mean the parent folder of the batch file not of the current directory of the prompt calling that batch.

Thanks


Solution

  • The parent folder of a Batch is in the Variable %~dp0 located. Example:

    @echo off&setlocal
    for %%i in ("%~dp0.") do set "folder=%%~fi"
    echo %folder%