此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
, X' W. t8 v' U2 ^4 }* v1 j 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
1 R1 x* O: k+ W, T: O 方式一:2 ~( g+ m5 c5 [
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
+ {6 V( N' D" t# Z$ Z% w 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和1 w) p% u d1 b( e+ ?
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
% Z9 `0 ]. c' \1 e2 J. K% X 方式二:& [( C/ s6 t% W. X
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 B/ F/ ]0 Z" Y
SetTitleMatchMode RegEx1 X6 t0 `) p2 w) A/ v- m
return2 [: E2 A5 ~# h* y# m5 C6 z" U
; Stuff to do when Windows Explorer is open
1 g1 Y8 S4 `$ {; V0 g T7 z4 s ;
) j% |, ?. z7 d, A2 s v$ c: q9 i K7 e #IfWinActive ahk_class ExploreWClass|CabinetWClass
! _4 j0 [6 Q4 Q6 l$ Q ; open ‘cmd’ in the current directory8 _ D# I. \6 r0 a7 f4 c5 Z6 M
;
2 W3 b7 E& e7 b# X4 _& p6 _ #c::: i8 m$ P( x+ m0 }
OpenCmdInCurrent()
9 K b! g/ L1 b. [5 c+ k1 N5 F return
3 N0 {9 z7 }$ v% g/ p* L #IfWinActive
8 ~4 Y8 `6 {1 L7 k& d6 [6 T( p: x ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.& O$ y) V6 l7 N8 g4 T
; Note: expecting to be run when the active window is Explorer.
( o& \2 [7 |% \7 L8 u8 n7 v: u ;
& S# Q/ I; f1 T6 }: |0 E4 M OpenCmdInCurrent()
I5 Y7 S: j! f: O5 Y {& R. J# b; ]! z& b% m2 N9 T6 S
; This is required to get the full path of the file from the address bar
+ j3 ^+ e4 _( y: j) N& h WinGetText, full_path, A
- w- k. P$ k; j {* Z+ j4 N ; Split on newline (`n)* N$ g! d: o9 K/ _: K7 s6 E
StringSplit, word_array, full_path, `n9 l% I v9 X: d! G1 U
; Take the first element from the array
) ^: g9 p2 ^" W' q full_path = %word_array1%9 u v. H$ R: e* a3 ^ A( m: I! G! A
; strip to bare address
8 x3 b$ n7 N" i* ~: ? full_path := RegExReplace(full_path, “地址: “, “”)9 @1 T+ }! D: g4 S
; Just in case – remove all carriage returns (`r)7 T$ s' I" p/ m7 j$ n( G+ v2 R. l
StringReplace, full_path, full_path, `r, , all. w/ j! k: o" h
IfInString full_path, \, h' x% M1 P% x
{$ ]0 L7 [, Q0 d2 `4 O' F. [# A
Run, cmd /K cd /D “%full_path%”
- F- n1 E4 `5 r9 a$ j }
) o" ], U( O. T' H: T else
. x0 O7 r! @ s {
( Y7 {) P3 E# Q: A& @! z& Q) \' O Run, cmd /K cd /D “C:\ ”
4 J& w& b6 ?3 y% K. s% L+ K7 I1 | }
; j' J4 ?) T7 I9 J! D+ P3 M( I }+ Q1 t2 n3 M* b# p8 d
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
( W3 c o. }* I( i6 Q5 o 这段小代码肯能有两个你需要修改的地方 @; _0 G9 H3 S1 y
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键2 e5 |- y5 h! I% \
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “7 D, T% A/ B4 J$ k
|