此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。, p) w y; b* ^' n0 v
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。2 ^1 y9 a K& v4 P5 `
方式一:
: D8 k6 W* h' @ 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
/ I: e* u1 I2 _2 i 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
' C9 `! k; D9 j( B* C# ^$ v HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
# {! Y) A) I* N( i, j5 L" ]4 J/ v 方式二:. o$ b: |; r! q+ P F, _, V; c
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- M9 d3 w( m1 e" M4 q+ G* a SetTitleMatchMode RegEx' [, Q3 O, o) R Z& B) T
return
3 }4 g( }( @3 b. u9 |" l1 n ; Stuff to do when Windows Explorer is open3 \: z8 r4 U' O( V9 m3 R1 w
;
5 }! R& e- x6 C9 \ #IfWinActive ahk_class ExploreWClass|CabinetWClass
4 F1 f3 O1 [$ M ; open ‘cmd’ in the current directory: @: g- L1 J4 p) a; Y6 I: A- I
;
a# e9 I+ y. U #c::
) O# u* m6 {0 i OpenCmdInCurrent(); g1 F) f8 Q, W: l
return
+ h+ o3 Y% n2 m b) \& P #IfWinActive# ~- n$ a/ G' T# T1 _* ]& N' L1 K
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.7 l; Q% c) r4 W' f; p+ k# ], a
; Note: expecting to be run when the active window is Explorer.
6 Y+ t J" g( y, w/ E* h+ K ;3 B$ U8 b* L3 K! u% y, r; `8 V
OpenCmdInCurrent()
, @; j7 f( c! Z {1 s/ g: ?+ G0 i8 c
; This is required to get the full path of the file from the address bar6 W* U, d0 \8 E5 Z# s. l" |
WinGetText, full_path, A
, g6 A. [2 @: A) Y8 D ; Split on newline (`n)
- p* | h6 L% q4 n& g' ~ StringSplit, word_array, full_path, `n$ x; d$ Z; `" T; {/ {
; Take the first element from the array
. P; H6 R+ W2 t' H7 M& B3 J& H full_path = %word_array1%
/ q& W C* c" f# c6 c7 Q ; strip to bare address* t) m$ |+ H6 S/ h6 ]6 F
full_path := RegExReplace(full_path, “地址: “, “”)6 R& n, h" R1 F( i
; Just in case – remove all carriage returns (`r)
3 \. S9 s4 w$ _+ z/ W" z8 G- r: z0 e StringReplace, full_path, full_path, `r, , all" t# M0 V' D9 s9 f& g4 y2 @
IfInString full_path, \
. J8 e6 k4 h9 q9 `3 t9 I$ I. m {$ n% h6 O7 K( z
Run, cmd /K cd /D “%full_path%”
+ p, D1 W) O/ }# Y2 W }4 _7 W! N+ l' w+ d: ?. f
else; Q# w8 ^) _8 S0 S
{
, W0 t J3 P2 x+ g3 S Run, cmd /K cd /D “C:\ ”' R# }6 E# z; ~# A0 P# B
}) b+ `7 @# \ a" ?2 }6 d; V
}" _- c4 k" E) Q+ a: f
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。9 D* m. V0 ~, d- l: h& N
这段小代码肯能有两个你需要修改的地方5 F r% J& A0 ]% ]
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键3 O/ O1 n% j1 _3 P5 v5 F
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “1 [2 F1 h( g1 O9 P( s/ _- K
|