此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。3 i/ b+ Y; w; b/ e2 w' c5 o9 a
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 g( k n# }6 n# g1 |5 v 方式一:
/ m/ A, t! n0 ~9 d4 F, ^ 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,/ X# \+ ^: O. s n
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
" j2 I4 A4 X1 ^4 e& n" k2 A HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
, u: N; g5 V9 a4 Z5 i 方式二:
" ^+ _1 @# A1 {6 J2 }! e 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
0 N7 R# Z4 h" {$ P, v SetTitleMatchMode RegEx5 x! ~: T4 w! y1 D7 y( i
return
/ \3 ^, a5 o$ W+ g. M* f( S' p$ Y ; Stuff to do when Windows Explorer is open
( |" s+ n: C3 T A; @/ g! X ;% U! E% }" a( {9 B, R" X# ]4 T, ~
#IfWinActive ahk_class ExploreWClass|CabinetWClass! L! @ A! F4 J5 q' e6 p3 i3 i+ q
; open ‘cmd’ in the current directory9 I$ C) T) Z8 _/ p1 V6 Z
;
# X/ i3 }, J3 z0 |" c" x, s0 ] #c::% B: Y y* M% Y; i( J3 S4 T3 T7 c
OpenCmdInCurrent()
( i; l# x9 w! M- a; X return0 u+ q, k r4 A3 j. K
#IfWinActive
1 h6 T( ^4 ~$ r& i8 j ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
& _7 k5 X/ _( H. V5 {: Q& l* N ; Note: expecting to be run when the active window is Explorer.4 b( @! H7 b+ I$ I3 J5 ?
;1 s* }, A {) E9 b6 U6 `% J& u, `
OpenCmdInCurrent()
% b, x& Q) L) `$ l8 z- z* t2 c& ] {
3 C1 `1 o# w; Z9 ?& f7 |5 a ; This is required to get the full path of the file from the address bar
$ C7 `! |0 r, Y5 X4 P0 B5 m WinGetText, full_path, A. B( D$ @! K" L3 r
; Split on newline (`n)3 Z g+ X5 o& a4 c$ ?/ v; G$ e
StringSplit, word_array, full_path, `n
# q5 _6 P3 X8 S# k! R2 A ; Take the first element from the array% A( |/ i2 x" c, r4 f7 e" ^9 n
full_path = %word_array1%
% Z( T6 K/ O3 {8 @# R9 y- z; g ; strip to bare address" z7 y0 C- p0 y, x3 q
full_path := RegExReplace(full_path, “地址: “, “”)8 y$ G; g: n" ?! d7 Q* ]
; Just in case – remove all carriage returns (`r)6 d: R9 K% q# _) U: x7 D
StringReplace, full_path, full_path, `r, , all
1 i) i3 m. r" d8 k+ B: \) l! u IfInString full_path, \
: k& f- m! ?0 D2 F2 h( W {: \# j2 ^; L" f3 s% X% p
Run, cmd /K cd /D “%full_path%”" N) s v& G& n8 V- i: N
}3 _! ]5 _0 X! [! f7 d t1 j
else; }$ u) V0 @# S. z* Z5 t
{
6 p$ ~- V" m# U4 H, u E Run, cmd /K cd /D “C:\ ”5 X) I7 ~: u% w; }- y
}
3 L0 _: ?! ]8 i) ]+ ~, W }3 ?; Q5 J; j, i+ B7 Y
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
% R) Q# x' t! |6 ^ 这段小代码肯能有两个你需要修改的地方/ H( D' g6 n- n8 \3 P, y
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
. Z* E* Q' k1 u* J5 L# b2 J$ ?2 U) k4 L 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “/ u( A4 m! d% G/ X& _9 ^0 |6 r& W4 ^
|