此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
& b0 W5 q' _) A: a3 K 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。2 ]- Z) v- A# o; R" U( p
方式一:0 k) K. ]. j' J6 @; N
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
# ~7 C8 U% {7 Z 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
9 M$ h% x# {0 o8 @) P HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。3 y i7 k/ [1 G
方式二:" H; C7 L0 ]: m Y5 Y% \
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:" O! v9 i# d& |6 Y8 `" u
SetTitleMatchMode RegEx# }3 `" m% w, h* c9 \( V
return
* t9 X v/ k1 p6 L4 ^8 n$ j ; Stuff to do when Windows Explorer is open* S" q' d F9 o, x! R
;
( e9 l. r, Q% Z% h) G* X$ S% p #IfWinActive ahk_class ExploreWClass|CabinetWClass) y0 L- \4 }) n- l) w' |
; open ‘cmd’ in the current directory
7 X+ Q) r) \2 q# t& o ;
* B" d, E& X$ v: B #c::
e, F* V: J. s: P3 v. u3 R OpenCmdInCurrent()
: B) @/ O( ^1 ^ return
% ^3 W0 u2 `# |/ {7 v' u$ w. u" _ #IfWinActive
5 }" s/ M9 [& m+ S5 v/ a) b ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
/ I7 ~: z; @5 k; E- z ; Note: expecting to be run when the active window is Explorer.. [, Z3 {. V: i# j5 p5 s
;( B- b2 q v t# j) [
OpenCmdInCurrent()- m. K+ B- l/ s8 j# _
{
9 ?, i, E% @# L ; This is required to get the full path of the file from the address bar) l, y3 w2 W! W% p' x) u4 ]
WinGetText, full_path, A
7 q6 O' O3 l5 G" e( c ; Split on newline (`n)% e* M8 P- E, {9 F7 ~
StringSplit, word_array, full_path, `n
% ?. h8 t6 g4 D# ?! Z0 e/ X4 l ; Take the first element from the array
7 m/ I$ s+ F& j& x3 L full_path = %word_array1%
' n" I, S/ }% H4 \ ; strip to bare address2 F) z: N, s1 Y. Q% g
full_path := RegExReplace(full_path, “地址: “, “”)$ P1 U$ n8 y/ i0 X5 z8 [! e7 k5 v
; Just in case – remove all carriage returns (`r)
. i9 S( |- a% \0 Y9 d# T* ]/ p StringReplace, full_path, full_path, `r, , all! V H0 _( Y$ H. A& O' w3 k8 B( A
IfInString full_path, \! \* e; I. C: W/ p0 `- t
{
3 x- m7 L" L; e; }& B. ^8 l Run, cmd /K cd /D “%full_path%”* x9 Z8 y4 T! I
}/ J4 b: T' j* Y+ l
else
8 R/ n( P, x0 ^. M' p3 r! E {0 {# E6 u) L( m$ c
Run, cmd /K cd /D “C:\ ”) h! q1 `4 g/ y! e! d1 R: f9 K
}9 Y7 \2 ?1 U" m# r* W
}& q9 E- [( w: z, j5 T# x) s \
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
7 w0 r. z; A: ?1 w7 R9 q 这段小代码肯能有两个你需要修改的地方$ D; x# z! g0 Y
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键4 t6 {; Y8 t( N6 t3 N2 @' E
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
) v/ S2 W# T9 g! d- i |