此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。7 Q5 b! T! L. y: f
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。" ?& j+ `& _2 Z: n
方式一:
& \% G q! G0 B4 m) L5 T4 ~% d 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,, q, w* |5 U' d+ r: Z$ J+ [
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和7 B7 K' Q. ~7 y7 A( f& y
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
1 i. ^- k( T/ [) ~) B 方式二:. u f9 L. V2 l$ K
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- c6 F# P( X4 v# N* `8 D" O SetTitleMatchMode RegEx, a% _: d+ S) v
return
# S: A9 N$ N6 q- T* A- Y ; Stuff to do when Windows Explorer is open
7 W( A8 V4 ^; w$ |& a ;
' S$ B/ [$ p w+ i+ v# R% E+ U, a5 O #IfWinActive ahk_class ExploreWClass|CabinetWClass2 L& t$ ]1 _$ O6 F4 h
; open ‘cmd’ in the current directory
& l* h! [4 a; [+ c) c, c ;0 n, Y# j" ^$ F! y! L N+ r6 z; A
#c::" m/ C& g2 x+ m+ l, O2 o
OpenCmdInCurrent()
1 N2 [: p' ^$ _ return6 W1 t: j! w% F+ l* _4 y( h' I
#IfWinActive8 l X9 Q, Q. \) h
; Opens the command shell ‘cmd’ in the directory browsed in Explorer." q# }5 [5 @! S; W+ s9 i9 q H
; Note: expecting to be run when the active window is Explorer.1 F- H C: @- o: i2 B
;
5 N% d8 s% g7 {. e OpenCmdInCurrent()
$ A* F: w6 k, ~$ |; x/ k {
3 x$ x; Y& t4 i5 H6 x ; This is required to get the full path of the file from the address bar2 j5 Y& G7 X4 ^1 Z
WinGetText, full_path, A: _" ^$ p( o9 j% G2 x( A& Z
; Split on newline (`n), S1 A: k8 G$ K: b0 ^
StringSplit, word_array, full_path, `n3 c z1 i4 P+ a& w; x
; Take the first element from the array
0 }( [3 w6 J n6 V' x9 p, E* I" } full_path = %word_array1%
& {% {) x- {2 H p6 Q$ y ; strip to bare address
9 G* f. ]( `" B5 Z full_path := RegExReplace(full_path, “地址: “, “”)
. `7 }" [. ~8 S ; Just in case – remove all carriage returns (`r) o& ?3 u2 ~' D$ x. G! T1 ~
StringReplace, full_path, full_path, `r, , all
+ W! D+ x; @4 c7 M1 b IfInString full_path, \
" C5 V) s0 f* f4 M' F% N: v( l$ x {
$ V# q/ n( x3 x# h: P Run, cmd /K cd /D “%full_path%”$ K3 ?7 R6 [ l: x
}
. ?; v7 J- d0 v' T1 q6 M0 \ i else
$ f& ^/ q3 o1 x% {1 y {
# ]0 H1 x# }% z7 r! O4 s- B Run, cmd /K cd /D “C:\ ”
+ f( S% w& |/ X }
c4 _* G$ P" y" m, T }& N( p3 w( N0 L9 S# n- p
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。: Z2 w- z: d) u0 ?3 R9 ^3 s
这段小代码肯能有两个你需要修改的地方8 f/ O4 b" P5 O8 m) J
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
) w0 }6 O# ?0 E6 t$ ~; D 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
/ w2 _$ q( o/ K- i |