此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
4 d2 ^# ]3 p- W- c. Q 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
3 b* q# q; f% G 方式一:- A2 s7 }3 B& I
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
8 _! ]4 i5 b8 A6 s9 Y. `" t 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
5 B8 C( V$ s& H. b' O HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
( L' s* Q5 b" M$ x! c: Q; j# o 方式二:4 c: f1 P9 g4 J
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:) u9 i0 S% }4 R* B) u9 ^) E
SetTitleMatchMode RegEx
5 \/ F& F8 a3 I9 X return( `8 d: l+ @4 a' g5 z5 g! h
; Stuff to do when Windows Explorer is open& Z. w/ {! Y+ M8 K! l& J3 n
;2 a4 @$ n2 I4 t% [) k
#IfWinActive ahk_class ExploreWClass|CabinetWClass; m3 A# n9 K* A# P, v, O
; open ‘cmd’ in the current directory
7 |& u6 x* ~9 g ;
t4 o3 R) e) Y$ H0 b5 t #c::
0 l6 ^ n8 V% n6 w# t OpenCmdInCurrent()
1 K( b4 l% Y2 Q' ?- J- K return
- D z# F+ P Q3 M #IfWinActive
6 {& Z/ g/ S4 W7 |" }4 g ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.* p. L9 b* o* R3 R% b( h: T' z
; Note: expecting to be run when the active window is Explorer.6 |- V ~6 M l
;
, b$ [7 c9 ^; ]- s2 Q4 T8 D1 y OpenCmdInCurrent()
1 ~% s3 V8 [+ }! {6 g& H( g {
! \" P" V4 k/ l. y5 K2 ~" N ; This is required to get the full path of the file from the address bar
, f8 y3 |! k2 L! U1 g WinGetText, full_path, A
7 i3 d4 y& Y9 e: T ; Split on newline (`n)4 L* J$ z; I: p) A$ c- k# b- S
StringSplit, word_array, full_path, `n
' A$ ?7 l6 ?" z* N) { ; Take the first element from the array
# E' t' ^- N5 b4 [7 x. w$ z full_path = %word_array1%# |5 L: z8 z$ G- c
; strip to bare address
0 X/ b* H5 Z- A: R$ r( h/ q% I full_path := RegExReplace(full_path, “地址: “, “”)( @& N- r$ E( C
; Just in case – remove all carriage returns (`r)2 Z% j: K5 ?9 c! m R
StringReplace, full_path, full_path, `r, , all1 }/ A3 ]. [: ^: g1 e( v! K7 j1 m1 S
IfInString full_path, \
) a( x- D; G/ d2 r" Y# i {6 a' V& ?; T6 A9 \2 \& {" N: ~
Run, cmd /K cd /D “%full_path%”
& z( r9 X8 }, R' d }
6 e* X @- ?9 p+ D! u( P7 S else
- a) o- w! o5 C( v& O {
7 f# a! p- M3 g! n. \ Run, cmd /K cd /D “C:\ ”8 O5 Y0 ]$ ^. H2 s6 D& R% `9 \
}, R i+ ?# V2 X. Z) I
}
& Y! u6 P8 X" h0 v8 H 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。; U% k( Z6 o! ]
这段小代码肯能有两个你需要修改的地方/ E. M( e6 [# C; L9 P2 r7 n* _
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键+ c' M6 U5 O+ z" V
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
; ^6 @( ?& V2 A9 {; W |