batch-file

How to express the following batch steps in a single cmd invocation?


Assume I have steps in a batch file as follows.

set dir=%CD%
cd ..\notes
dir /b *.tex > %dir%\log.txt
cd %dir%

How to express these steps in a single cmd call?

I attempted to call as follows

cmd /c set dir=%CD% cd ..\notes dir /b *.tex > %dir%\log.txt cd %dir%

but it did not work.


Solution

  • This should work

    cmd /c "pushd ..\notes & dir /b *.tex > %cd%\log.txt & popd"