此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
+ R$ k X5 |- a5 o& Z x 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。" y' J2 E' D. g/ k, k( I0 y
方式一:0 ]2 y: x7 h% u, r* z
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
. V l7 }8 B3 F3 P0 H 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和/ Y/ z- z! _: P! M# _' P
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
) t" n* g, W8 q3 z, l 方式二:4 f0 y; _. O8 d- u
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:1 e0 A/ t) u, B
SetTitleMatchMode RegEx
% H0 `$ _6 _) W' B/ a+ { return* v8 ]" y2 g' F. s$ s. v1 a. N
; Stuff to do when Windows Explorer is open
: b" U1 I* W6 |9 D* b& K0 j1 r" { ;% L# P; U% p5 B0 z+ i9 _3 g
#IfWinActive ahk_class ExploreWClass|CabinetWClass
8 B* r, f. J. T/ ^3 W* P( p9 I* W- @: l; | ; open ‘cmd’ in the current directory
$ U: q' F9 V% L ;
{7 F# x# H# C" F #c::
2 Z |8 s, m1 c% Y8 e" ~ OpenCmdInCurrent()5 k' V$ @* ]5 f+ _2 }$ c
return$ Q8 `. l; B' z* X) i
#IfWinActive5 S( A# n6 c' T$ q- @5 T
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.* d j! j( Q; G# c) Q \. v. j
; Note: expecting to be run when the active window is Explorer.& K1 H" a3 K/ o, ?
;
$ J1 T2 i1 L* A0 R OpenCmdInCurrent()
, \+ y& u2 b; t; Q; d# j' G4 |9 c {( ~5 [9 z: Z' n- Q* @0 h
; This is required to get the full path of the file from the address bar) v* }8 f# ~0 `" i3 r
WinGetText, full_path, A, ]* T; q3 F9 [8 K5 |+ j
; Split on newline (`n)8 t0 T9 \) E5 y8 c: m+ n
StringSplit, word_array, full_path, `n
0 G; l3 \* [0 a# l3 v8 n ; Take the first element from the array
% y/ t0 |: M3 X9 D# v4 e* ? full_path = %word_array1%
, w! g: \' P2 t: X& e ; strip to bare address
0 r+ T. r+ m3 ~' F1 ?/ S2 e full_path := RegExReplace(full_path, “地址: “, “”)) f( @. u, j: v2 t* @! f' | Y& V
; Just in case – remove all carriage returns (`r)% T( q" s, d; I9 r, T
StringReplace, full_path, full_path, `r, , all2 Q3 v; |" M, F6 F" x1 H, X
IfInString full_path, \
! R/ @+ d6 l5 \& | {7 L! q5 {0 k8 P6 o) S2 N# j
Run, cmd /K cd /D “%full_path%”6 v8 U, B# @" D/ Z7 d. x8 j7 I
}
2 J; n0 E/ t# e/ Z' J else* D- d" S/ N" H. T0 s8 Y8 m5 p, [7 ~
{: S* A$ ^9 I5 I, [2 H/ K' a% c
Run, cmd /K cd /D “C:\ ”+ w, N' T" r3 Z' R
}
9 h" C+ U& O8 q: n1 h }
$ l9 H3 ]: j( t0 G4 _, s$ ]; u 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
2 H; x1 T0 J; t; j4 |5 r 这段小代码肯能有两个你需要修改的地方& Z8 B" h2 D; K/ p6 W) d' v2 |8 f
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键" H. p# ~# j2 P
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
# u, L- @+ g8 T0 ~( L s |