此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。* D/ h- t. Q- `
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
( v7 u6 |% c3 M: i9 i3 Z 方式一:
: I4 r# _. c! a$ w2 q' } s 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,$ d/ W. N9 ^ ?' D' P1 i
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
6 ~3 p2 \( \4 h1 A- }$ G& P: a HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
! A$ E6 v3 K* b. ]6 v& Q) z 方式二:2 X/ x/ M" Y7 B' p0 C
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 L9 P: s& ~4 r& i- R* B' _$ h" [8 S$ Y7 p
SetTitleMatchMode RegEx
+ N- C+ r: E) i: T8 p" E8 \ return! n8 ?" R7 N1 ]" A3 C& \ V2 F
; Stuff to do when Windows Explorer is open9 I& @1 x. n! @8 {* `
;
- f, K( G0 L4 m4 Q. l0 Q, n #IfWinActive ahk_class ExploreWClass|CabinetWClass
5 h1 `/ t8 g; G& F M ; open ‘cmd’ in the current directory0 h2 I7 l5 \/ L' r
;1 m+ Z, V* ^: F. C6 f* @4 r# M6 N9 O! {. t
#c::' S' q& P1 ]9 }
OpenCmdInCurrent()
% V( k0 q, }* e return' u% i' O, Q3 b1 }% A6 ]
#IfWinActive$ k' \' J/ B+ o/ j/ b
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
1 G3 a5 g5 j! h1 Z$ U3 a2 _ ; Note: expecting to be run when the active window is Explorer.
0 b& G1 i% [# C ;
9 a- k+ m" ^0 G: M( t. n, z OpenCmdInCurrent()
* J; M/ {7 K2 n8 p {
8 |* G- f4 n, k% ~3 e ; This is required to get the full path of the file from the address bar' g4 b/ z- v n" ^6 {
WinGetText, full_path, A
3 k( O; W: i7 V) j* G# M+ y ; Split on newline (`n)
% ]) Y. }/ X5 R# h& u StringSplit, word_array, full_path, `n
8 T- J6 e0 W! l, Y! P0 x% Y ; Take the first element from the array
0 O: c4 R: U* ]: C0 R/ j full_path = %word_array1%" S* \5 n! n. o6 i9 D7 b
; strip to bare address
$ t) V4 N, W K, U9 h full_path := RegExReplace(full_path, “地址: “, “”)
* v# F8 e! S& l. t6 f& Y: j7 v ; Just in case – remove all carriage returns (`r): S3 w7 o, {' O% c
StringReplace, full_path, full_path, `r, , all* T: q s& o8 Z
IfInString full_path, \& ?* @7 z1 Q' ? k5 G3 x! K- E
{) \) }- q* r" H; L# w; ]# f
Run, cmd /K cd /D “%full_path%”
' ^- S! g8 ]- s1 m0 Q }
2 w( @. Z8 ^3 Y, s1 [; A1 ? else
7 {: I% m' @! c: D: X7 I! I {
3 i2 i" U' U$ }- N5 w: v+ M Run, cmd /K cd /D “C:\ ”$ x7 ]5 n/ J+ U# V9 S! n1 d
}
+ e2 A9 u1 z! n* V' }, R4 w }
! I2 }: F% z ]6 ]* }6 l1 g3 l 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
4 s5 \! W- ]# n1 l 这段小代码肯能有两个你需要修改的地方
' m, G& @7 b5 Z# l7 Q 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键0 D4 V- y. C; M; {( L# A
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “+ ]! c6 Q' a4 J. c( N0 h
|