此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
; f) J* ]1 k& B, u5 } D& s 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
# |5 g% q3 m6 X 方式一: k6 g! ?$ F, r9 f
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
9 w. o: i- z3 B& J 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
, \' H. B4 y4 R& r0 J/ P HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! X, J6 f9 |; m, Q4 i
方式二:
- q- Z; m5 Y; W( w, s0 A( s- l8 ?8 d: z 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
( F4 A; x/ A" [: z3 q SetTitleMatchMode RegEx
" o. X! u0 U5 l& s) I return1 Z- D' W0 k% l' H+ O; `0 }3 j. G. u
; Stuff to do when Windows Explorer is open
( B8 `+ v" D* T) `% ^1 \/ R ;1 w# ]6 k' E' A' ?8 D+ r! q5 M
#IfWinActive ahk_class ExploreWClass|CabinetWClass3 W/ H+ E( p% ]" P4 L3 t" U
; open ‘cmd’ in the current directory
5 [' u2 d, V5 ~: a+ t" W' Q ;
. y1 Q t; v r! O! i, _ #c::
+ @8 _5 B8 W( i5 x, b: o OpenCmdInCurrent()4 T* d1 e% V) }3 W
return
1 K; ^+ n Y% z #IfWinActive& u3 I' |: L) M! P/ q
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
/ u( s0 F6 k8 R ; Note: expecting to be run when the active window is Explorer.
. _/ i5 E) e8 w ;8 f+ `1 X6 @5 N7 w) L
OpenCmdInCurrent()
( P3 {& ~: h" o {
" ~6 _ e. o) o$ }5 T4 W1 X8 | ; This is required to get the full path of the file from the address bar
5 H6 p" x4 Q- f$ t5 z) }) I WinGetText, full_path, A2 a- P* d2 J y; H" s
; Split on newline (`n)
9 D9 A' ] u1 [3 \7 t StringSplit, word_array, full_path, `n( Z' I# e6 T$ q2 r7 p, w
; Take the first element from the array( i9 U3 w* L* ~. u8 K
full_path = %word_array1%* e2 N8 a" [* j: A
; strip to bare address( z' ?# ~* Q# X8 U$ C3 @
full_path := RegExReplace(full_path, “地址: “, “”)# X2 D4 S8 \2 B e
; Just in case – remove all carriage returns (`r)0 s* Q, r+ @6 p |% c
StringReplace, full_path, full_path, `r, , all! Z3 V" L# |% T0 v% [" q- N; |
IfInString full_path, \& d) p! `; H) y3 R9 S# e% O3 w
{) R4 _( `- i" v& K% k
Run, cmd /K cd /D “%full_path%”
) u0 b* g6 k& X }8 y& W- w8 s4 x- t
else
+ C; [, K9 I- ]) D9 R1 r. T {
4 x8 Q6 U$ J( P+ I( N- X" ]. u Run, cmd /K cd /D “C:\ ”
" B2 Y. S Q; A9 O$ q, L: P8 d }
" F9 a. |7 u$ X/ g: k }9 H9 |; K; D s' Z) F3 N _, D
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
U+ X/ V; `4 ~ 这段小代码肯能有两个你需要修改的地方
. @( @6 L ^( i 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
) j4 @8 {5 `& N7 N M 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “, H' A" [: x! f+ \ w4 o$ N
|