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.

本文介绍了一种在Windows命令提示符中返回上一访问目录的方法,通过创建自定义别名实现类似Linux的'cd-'功能,并提供了一个简单的脚本示例。同时提醒用户注意避免使用特定的盘符命令来改变驱动器。

5万+

被折叠的 条评论
为什么被折叠?



