此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
# x/ N" d# F3 ~0 l1 G 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。9 n5 Y. q( h0 V7 [1 G; h- g1 k3 X& B
方式一:
+ q- e3 Q4 @8 [+ T# Q" r$ t 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,2 I( X+ y3 Z* x
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和" j6 ^' i) \! f$ |
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
* g: I/ c: z3 n2 `7 o+ f 方式二:9 t# L! M1 H( j
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
! f ?. b, P4 {4 j* b SetTitleMatchMode RegEx/ P6 C" j2 P! R& p0 b3 Q5 g
return2 `) D& p* y: L
; Stuff to do when Windows Explorer is open
# y: m) r% I/ \ C ;: b) S( D2 q4 r6 c, w% L# {
#IfWinActive ahk_class ExploreWClass|CabinetWClass
7 B1 R" d7 f- O% r ; open ‘cmd’ in the current directory* g2 t; Q. o9 I% G+ j
;
0 i; M* Q9 h% P/ T #c::
: H; n( a- O7 U OpenCmdInCurrent()' X n: a& i4 z" V. O' ~6 i
return7 |# B! o( x7 T6 d4 f* o
#IfWinActive
$ }) ?" M1 Q! o0 v3 ^ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.) ?* `6 d" }4 W# }
; Note: expecting to be run when the active window is Explorer.
% h1 e1 s( g5 V1 }( f ;* s) Z* O/ Y: r8 K7 |
OpenCmdInCurrent()
2 P5 `3 ]6 C1 @3 m( `3 @ {; O' n* O" ^% A! Y; W
; This is required to get the full path of the file from the address bar: i& I8 k/ t( Y% v
WinGetText, full_path, A- A2 G6 E$ |* @7 h# Z6 I
; Split on newline (`n), Y' _2 }; c5 { ^, v$ J( {
StringSplit, word_array, full_path, `n
. N2 p* k; }- Z; x& G4 [; K8 Z ; Take the first element from the array2 X6 h, L% F6 h' `5 L
full_path = %word_array1%* O( {% S/ T B: {* |4 T& L
; strip to bare address- `9 B4 r8 l% a: r+ p+ e0 j h
full_path := RegExReplace(full_path, “地址: “, “”)7 G1 b- j: z: D6 R/ n/ _2 e0 L
; Just in case – remove all carriage returns (`r)- Y( }+ g+ {0 {6 b! R$ R. A
StringReplace, full_path, full_path, `r, , all# q3 w( c, R; z% ~) r5 h
IfInString full_path, \ i5 c. ?6 @9 T2 o
{. W& R9 ~, v. [* K& ]* {9 U
Run, cmd /K cd /D “%full_path%”
* v" {' i g" e& { }
, o) D: ?% V( C. _* S else' _ ~+ C% h; C% \ K* F8 T
{. L7 ?( r2 F$ a" S
Run, cmd /K cd /D “C:\ ”
# w0 B+ G3 w5 r; |+ Z }: y/ I K/ p: ~
}+ [; o- {4 {) K1 v
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
+ [. G3 J0 v2 T 这段小代码肯能有两个你需要修改的地方7 T$ ?. K, G" X C. o; I
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键% O* |" l+ l" i) ]% \
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “1 p/ H+ N* j/ g: C7 Q4 ], F
|