Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Definitely PUSHD / POPD is the preferred way to do this. But there is a (undocumented?) feature of SETLOCAL / ENDLOCAL that accomplishes the same thing (in addition to everything else SETLOCAL does).</p> <p>If you change directory after a SETLOCAL, then you will return to the original directory upon ENDLOCAL.</p> <pre><code>cd OriginalLocation setlocal cd NewLocation endlocal rem we are back to OriginalLocation </code></pre> <p>One other thing with SETLOCAL that <em>is</em> documented - Any SETLOCAL within a called batch or :label routine will be terminated with an implicit ENDLOCAL upon exiting the batch or routine. The implicit ENDLOCAL will return to the original folder just as an explicit ENDLOCAL.</p> <pre><code>cd OriginalLocation call :ChangeLocation rem - We are back to OriginalLocation because :ChangeLocation did CD after a SETLOCAL rem - and there is an implicit ENDLOCAL upon return exit /b :ChangeLocation setlocal cd NewLocation exit /b </code></pre> <p>I wouldn't recommend using SETLOCAL/ENDLOCAL instead of PUSHD/POPD. But it is a behavior you should be aware of.</p> <p><strong><em>Response to johnny's comment</em></strong></p> <p>It can get confusing when PUSHD/POPD and SETLOCAL/ENDLOCAL are combined. The ENDLOCAL does <strong><em>not</em></strong> clear the PUSHD stack, as evidenced by the following:</p> <pre><code>setlocal cd test @cd pushd new @cd endlocal @cd popd @cd </code></pre> <p>--OUTPUT--</p> <pre><code>D:\test&gt;setlocal D:\test&gt;cd test D:\test\test D:\test\test&gt;pushd new D:\test\test\new D:\test\test\new&gt;endlocal D:\test D:\test&gt;popd D:\test\test </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload