此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
0 u# i/ D0 S; i) H5 ]% F 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
" e, Q( n: F. ? 方式一:: W) G) U. H& P0 K) f9 b% c& H
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,- d! G- R9 e( k, K
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和- {+ F" F8 E! l" b. v: w" v5 {. B
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
, g0 v1 W" g! a2 [$ L- v5 X 方式二:
! j4 ?: e0 I m: W) T) O/ `; W 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
* w% w" u1 O; v' S; I9 ^8 s2 l0 N SetTitleMatchMode RegEx b" i! ?! a8 B4 Z" S% m
return7 }% E/ f8 y0 B2 A! l
; Stuff to do when Windows Explorer is open+ W; I ~/ j( V
;1 n, o7 E: H+ M, S8 A
#IfWinActive ahk_class ExploreWClass|CabinetWClass/ E9 ?+ f1 p9 `& b6 Y* J" z$ I- U
; open ‘cmd’ in the current directory
O' x+ V% r& m' \! b( ? ;2 w1 B" S4 D) n
#c::0 w* ?# [' o( d% ~, X0 N
OpenCmdInCurrent()" s- \1 p/ K; e5 l/ n
return' |, Y! v$ C3 C
#IfWinActive
! z9 _* u5 h% S ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
" F* R: S! V( M" e$ B9 ?- D7 U ; Note: expecting to be run when the active window is Explorer.
% e- V7 W, K8 k, t2 _8 r t7 `+ h ;2 X% i: @' s% a5 i t8 N
OpenCmdInCurrent(), G# s0 A2 @) i$ c5 n
{. n0 S) r! X# U( e: d
; This is required to get the full path of the file from the address bar* U. c4 h" u; a7 z* W S& C# ~
WinGetText, full_path, A, P7 D# _9 }4 |1 U9 ?4 z
; Split on newline (`n)
5 E& Y- R$ L# g( ?2 z5 e& I StringSplit, word_array, full_path, `n1 {$ N8 D$ g. X) ~' M+ m* W
; Take the first element from the array) ?; q$ h, \, N, G9 b; x
full_path = %word_array1%
$ L: m+ w/ [9 m+ A" ~$ h ; strip to bare address
1 T( ]& o9 x6 [' \ full_path := RegExReplace(full_path, “地址: “, “”)! P& M2 x# P* U; g0 |
; Just in case – remove all carriage returns (`r)
) Y& `9 }9 M# @3 W% Z2 f0 Z StringReplace, full_path, full_path, `r, , all( o9 C# ?4 |+ c' ^1 U9 ?5 T/ E
IfInString full_path, \
5 _0 @& o4 Z) ?, ^% u& n {
" W2 H" G& F: J0 ^- u/ C; w Run, cmd /K cd /D “%full_path%”- u2 V: Y- c, e3 J/ t4 [" P0 @% u
}% ?' \8 y4 s$ d U
else3 J; {4 x' o9 @8 g; G, t. d6 C
{
+ {# Z0 W. E* D1 R( K2 |9 n* s Run, cmd /K cd /D “C:\ ”* {3 h7 Q$ ?- t1 d7 m! }, r0 m8 O
}9 R* k) A/ }1 W w6 o4 T
}: y( |3 h* t5 b
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。& |. _) u( C0 N# v: T
这段小代码肯能有两个你需要修改的地方
) I$ S1 Y( m m) f 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
, ? i3 Y+ K& _ 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
$ h4 D7 H6 R" G1 Z9 B5 v: z |