此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。" u3 k" `1 _! o* F+ W+ T e3 k
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
, F6 X( l2 o# u; T2 H7 E 方式一:
6 w' G1 R% P3 F9 G/ z* ~9 a 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,) K4 c8 h# ]- `6 |
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和- I }9 V& j$ p9 _( Y
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
( D' r* e [( O! }6 K+ p; z 方式二:. }* j3 E* X) t) S: \1 B+ F, b
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
9 m/ Z& x9 r' P0 x, g$ }1 F SetTitleMatchMode RegEx: o9 p2 z4 S$ C6 {# P8 ^
return8 R+ S3 o, o0 P6 X
; Stuff to do when Windows Explorer is open. _7 U" S0 `/ J% U
;* Y6 n1 d4 u [8 \0 G' w, ~9 p
#IfWinActive ahk_class ExploreWClass|CabinetWClass- b1 s" @, [: B+ q% |. n d
; open ‘cmd’ in the current directory3 l. L5 F* x9 C1 Q$ A6 m
;
- h+ O; Y3 p; ^4 {! n #c::
$ }9 A0 k$ W+ }0 e7 W$ U OpenCmdInCurrent()5 Q$ L& \. m b1 J: K* }+ [" `
return( L& ^ ~3 f- L6 h+ u, V. n- ]& T
#IfWinActive
- H+ C" J8 _! W5 F, U2 L+ T ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
M% ~5 b5 z, n$ l- | ; Note: expecting to be run when the active window is Explorer.7 V' P$ N |( ^2 Q
;
1 X" k/ E2 E+ R7 r OpenCmdInCurrent()$ M2 M! o# i( U& I: S; A* n9 W! s
{! [) E2 y- P( w, g2 g
; This is required to get the full path of the file from the address bar" ] s% l4 |( w; K5 Y8 E
WinGetText, full_path, A
8 M3 C4 M$ J. x2 B/ t ; Split on newline (`n)
! |9 O" c- R$ z$ W StringSplit, word_array, full_path, `n
8 ]6 y! {0 b1 b0 V ; Take the first element from the array7 d* }9 n" p( Q" m
full_path = %word_array1%
4 k7 v# @9 s' O* J4 `( c6 g ; strip to bare address
+ f8 V6 G Y# V6 I+ f9 ^ full_path := RegExReplace(full_path, “地址: “, “”)4 e7 f% o) N# X. I* W, q2 ~$ q
; Just in case – remove all carriage returns (`r)
) @$ @1 |6 a _" F9 `; m- q StringReplace, full_path, full_path, `r, , all7 b( t: ?2 ]8 x9 F3 B) q
IfInString full_path, \
! @* T/ l4 I2 y; E" x3 c# w g {0 I- o6 V" y6 U" g' ?
Run, cmd /K cd /D “%full_path%”
+ G; v0 A x8 \# W: L+ C; i }6 G; n( K( z( D) f! b& A2 b
else k3 j0 o% e' ^2 C( U9 ]3 Q$ j
{
9 R7 ~& u3 u( g) d" p Run, cmd /K cd /D “C:\ ”8 \; @3 Z+ T% f0 O& m4 i
}+ O4 R1 b! g! ^5 p( @! Q, ?! A! p, k
}2 ], }/ V* W- ]+ L' i7 x
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。6 Y# S7 K" ~: `5 N
这段小代码肯能有两个你需要修改的地方! f: ~1 p% t; s* X
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键. H( Y7 u: A, _3 O/ [
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
' a8 T1 G' q+ |( k# M2 _: G, j |