tools - windows cmd: cd - to last directory

In windows cmd there is no 'cd - ' where in Linux which means return to the last visited directory 

however, you can make some alias in such as way 

@echo off
if '%*'=='' cd & exit /b
if '%*'=='-' (
    cd /d %OLDPWD%
    set OLDPWD=%cd%
) else (
    cd /d %*
    if not errorlevel 1 set OLDPWD=%cd%
)


and may use doskey macro to do some alias

C:\>doskey cd=mycd $*

The only caveat is if you omit the space between cd and .. or \, you will get the builtin version ofcd not the doskey macro... and you still have to remember not to use C:D: etc. to change drive.

Please refer to the origianl discussion on "Navigating to Previous directory in Windows Command Prompot" from StackOverflow.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章