此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。% D3 {8 }- R) t1 |4 b3 m
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
; c. r" M, s/ h5 Q% h2 { 方式一:% f; I! Z# k3 a! Z
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,/ I, b8 J3 B/ w; [" z' Z
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
2 E+ t; q" n6 _$ g# x/ A" K% a( M HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
8 v) k$ z8 u: c9 J/ f 方式二:
& v, r1 B" k S; A$ }, E# _; m 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
* v. s' h% y. W SetTitleMatchMode RegEx
- j1 g: |. J* U; P( G j& v return' m F% y6 I {6 H5 D( S
; Stuff to do when Windows Explorer is open# h d: n: G6 U$ Q: f U; L9 l" ^
;
' l* A8 r, ~0 Y- b #IfWinActive ahk_class ExploreWClass|CabinetWClass
7 C' j4 a7 r) S7 L5 O ; open ‘cmd’ in the current directory" S4 P0 z8 r& x
;; `! o" P: {: J
#c::
7 Q- z) w' {2 I& F6 T OpenCmdInCurrent()' X9 _1 V0 i; L( B) f
return6 J: c8 d- R2 a3 T/ m
#IfWinActive
/ l, {4 a" A0 V; a i ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
+ N# |' Q; k, s2 }' I5 Y- ~ ; Note: expecting to be run when the active window is Explorer.
7 G. s! }4 s4 h8 n" \4 f ;
7 v! Y) E; j% _; ]& k, Q3 l; } OpenCmdInCurrent()" L9 Y! ]& ]1 g4 f: r
{: F# j: H. K4 W; v& A2 p% \. {! ]4 r
; This is required to get the full path of the file from the address bar0 v w3 }0 h5 M) G* x6 @# V
WinGetText, full_path, A& A$ t. L2 r6 P1 u4 @3 _6 D3 B
; Split on newline (`n)
j9 N/ e/ Z' B8 I" q+ u StringSplit, word_array, full_path, `n
4 L& V/ w0 m0 P! | ; Take the first element from the array* Y" J0 w1 P1 V% ]% C
full_path = %word_array1%
/ M8 B7 ~5 D |2 e `, K* P ; strip to bare address [. Z3 k$ }& y& x- ]$ \4 p
full_path := RegExReplace(full_path, “地址: “, “”); Z# g5 S+ B! F: ~* \
; Just in case – remove all carriage returns (`r); X4 |% Y. ~# i* G- Y. B- c( } S
StringReplace, full_path, full_path, `r, , all
* `. i1 }) P! |( D IfInString full_path, \! {7 v# e8 h' k5 N# @ m5 f0 U' w
{
0 X, J4 [. D' b& m# @$ t3 @: j9 c Run, cmd /K cd /D “%full_path%”
8 B$ l3 n( L1 k2 `7 E: k) H }
; E! T) y" o c; j8 N! U else' x6 m1 m5 w0 [9 \# W
{
# o( R7 i6 P8 ?- | Run, cmd /K cd /D “C:\ ”* K: m' H5 ^3 D; t. R
}9 y x' x- {. c& j; l% S
}2 [9 J/ w+ K5 I7 _, X: g* c
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。1 z" {$ E' E9 A
这段小代码肯能有两个你需要修改的地方
; H6 H6 x) h/ t$ |$ P; v 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
6 Z7 I7 G# x- R0 r# l& O ]4 V) T 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “/ s* G+ s6 _. [# e: M2 i
|