此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
4 i3 c$ }4 Y& y1 d/ a 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
( A- G- {* @% I' O) ]- D2 [3 X& V 方式一:
9 `4 d) J( ~& o6 ? 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
& e) t5 M- c0 S$ J 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
7 r. {, ?2 n9 Z) N. ^ HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。8 c+ R- X3 y# b* z
方式二:) u" v( e$ X I: d
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:. Y8 }8 f0 N0 {7 F
SetTitleMatchMode RegEx
. ^; w) e4 r" q, }) }" v return9 n. A$ U' X" P% b% |
; Stuff to do when Windows Explorer is open
$ c% F( A+ v/ j- |; s0 B ;( W I" w3 e/ e% W# ?
#IfWinActive ahk_class ExploreWClass|CabinetWClass& |: t& e$ b2 c9 Z
; open ‘cmd’ in the current directory
) L* x! N1 [ ] ;
) X) \3 K! E: J #c::
* s! ?; g- w- w! L5 R; e/ x( T OpenCmdInCurrent()% [1 ~9 l' @9 ]4 P$ w
return
& U4 C$ B- m3 ~" f) D( Y$ p' W #IfWinActive6 t' j2 Y, O- ?, B R; R
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
1 F; w' o$ Z7 ^( M0 t ; Note: expecting to be run when the active window is Explorer.
3 P$ b) y2 _" p ;
8 w( y3 h/ P6 z, x: ] OpenCmdInCurrent()
* }( K. b/ R- D: Q% K6 j {
4 a' _; f# D, y6 g ; This is required to get the full path of the file from the address bar) f. y" ?0 p* j/ A$ z5 o
WinGetText, full_path, A( ~, i: Y' u; {
; Split on newline (`n)
* a7 n6 b& Y# f: q StringSplit, word_array, full_path, `n
5 [9 ]6 ^9 v0 a4 o0 _) c7 S ; Take the first element from the array' V/ _! P) \7 I( s0 T
full_path = %word_array1%
1 C2 m9 n3 b9 v a& {% A, t. r ; strip to bare address# m: X7 p5 \. V* \/ t
full_path := RegExReplace(full_path, “地址: “, “”)
1 L$ `) Y9 K2 k a5 X3 e ; Just in case – remove all carriage returns (`r)
7 t) k; p0 p. u) M ]5 S StringReplace, full_path, full_path, `r, , all6 ?2 \2 T& A5 w H8 h4 x" p( a
IfInString full_path, \
! o1 G& y9 F! w' u5 j {& z" @* @3 C [. n
Run, cmd /K cd /D “%full_path%”
5 b0 i: a- F4 W7 ` }* h# r k* s3 C
else( U& N5 d1 a" O% a9 h) z" x
{6 d: g, Z$ H; f1 y! w \& Y
Run, cmd /K cd /D “C:\ ”7 p: ^ X! z9 Q0 D" N
}
& g L/ w* i8 c& T0 i }/ k- N. i9 i9 B, ^
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
9 y, u; G" c% U" y, A4 q0 L+ m+ X 这段小代码肯能有两个你需要修改的地方
) p' q6 x( m0 c1 H! e 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键: I4 F0 [0 m! e3 W( R4 e( g- f
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
6 J8 v& t8 c9 ` |