此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。/ [& J" [9 k/ D! G
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
. J: \1 E, k) z. K6 P( |- k 方式一:& p2 i: b: l! G
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
$ a6 @ p- L% R5 `' c4 Y% J 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和' b! S; a+ X( I- ?5 O1 i
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
) e( T" {7 {" W! X, S: A 方式二:
' j3 A) o5 f1 ~' Z. @6 G# G, E 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
4 K$ O8 w# w' q2 F8 K2 d SetTitleMatchMode RegEx* B1 O' \( x" O/ I3 B
return! F, u' d4 g6 K5 z' W% v1 Q( i
; Stuff to do when Windows Explorer is open
+ H0 ^0 \9 c" Z( Q ;
3 b, [& f! V: C2 s' k# d' n #IfWinActive ahk_class ExploreWClass|CabinetWClass0 n( E( d% E. x/ p
; open ‘cmd’ in the current directory l9 o$ K/ z* ?/ N) l m$ c
;8 @+ `& Z; K3 b1 P Y7 f
#c::0 O# q5 |1 ^8 c9 s' j
OpenCmdInCurrent()% X& ]8 Q9 c F, c* l
return9 L- u- y5 [. J6 M, \( |" L
#IfWinActive
1 ^/ b( J4 _7 @! t; Z ; Opens the command shell ‘cmd’ in the directory browsed in Explorer." @. I+ E: T6 f. a* f
; Note: expecting to be run when the active window is Explorer.- _: i3 W# x/ W3 y1 h5 Z$ n) s
;1 e+ v7 F" k% `* D" M3 X' }5 o9 P
OpenCmdInCurrent()* j* p9 T" |" n9 }0 r3 M
{
0 a+ B) S; I7 Z- ?7 [7 s- v+ q3 \9 c ; This is required to get the full path of the file from the address bar
! p1 M2 g+ \: }# j WinGetText, full_path, A. C# R) F& @5 V P8 k g4 n! i
; Split on newline (`n)- q% i5 m5 ?, g( d" W3 n
StringSplit, word_array, full_path, `n
" G7 l1 p" m5 F9 r" Y( l8 ?2 l ; Take the first element from the array9 c- c# ^" O* O+ p
full_path = %word_array1%8 C. s& \+ v0 W0 R
; strip to bare address$ k( z2 |8 e2 B
full_path := RegExReplace(full_path, “地址: “, “”)
6 c1 o4 w) U" d% Q4 p% \6 [4 W ; Just in case – remove all carriage returns (`r)3 Q8 f, @% a( i
StringReplace, full_path, full_path, `r, , all7 u; j% [: @3 }
IfInString full_path, \3 n# T7 A7 g0 W4 |* l. r
{4 V' A% l% s: M7 q. U
Run, cmd /K cd /D “%full_path%”1 G: W! i. C! K. J
}) {+ X' V9 O3 l2 b! R: w# A/ z
else
: a& q4 F* I, s5 O/ ?* ? {
6 ~% ?' V" t6 C6 o D" ^ Run, cmd /K cd /D “C:\ ”2 r# x( s) b3 j+ R, b
}
5 y1 \. P6 {4 Q }( q7 L& q; K0 Y5 v# i: ?
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。. y$ s. t8 D5 I8 s( S; d' u& h% m
这段小代码肯能有两个你需要修改的地方
6 C# e8 U! m+ m 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
& W, k$ Z6 |- O1 f- r7 w |8 \0 B 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
6 D+ A5 N. K: k2 i3 l1 z |