此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
& R- q X! R, v( s 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
& ^/ F/ a* E% w4 ]5 Y8 E8 J1 V }* v 方式一:
1 {, W; U) }) H/ T C4 I 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
) ^) }# y4 {& u 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
9 L& J" q9 w5 a/ I; n3 a# M HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。. A b" S; b% A2 v
方式二:& l# H% R* e' r& ^. Z6 z p
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
; i6 E9 s1 b+ O8 O SetTitleMatchMode RegEx o+ D& p7 P6 [9 r
return" N5 [% t# m$ n/ _5 F
; Stuff to do when Windows Explorer is open$ c1 j- Q8 p/ g! d( S
;
0 |" S2 s; t# q8 h( g( M #IfWinActive ahk_class ExploreWClass|CabinetWClass
4 T2 P7 C3 \6 P! T- d! j1 g ; open ‘cmd’ in the current directory3 {: H& }! U, Y" M: C, d
;1 ?6 Z) H6 o4 a5 g. b! I( L& P
#c::) u T; Z2 k' l$ K
OpenCmdInCurrent()
+ L. e6 g6 _& e6 N; p0 V return8 T: c% f) @: N2 G' S! F4 m. b
#IfWinActive; B) R( e9 {- P
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.- u- X% S( v: X$ G
; Note: expecting to be run when the active window is Explorer.
7 }5 w( \! y' s5 v+ s* ] ;
$ p! L) A" S% e6 y+ k OpenCmdInCurrent()6 T" I+ E3 S$ E. |2 N
{& m3 B, }2 @- i+ Q8 b
; This is required to get the full path of the file from the address bar
: i0 D$ p1 g( C WinGetText, full_path, A# V+ ~( ]8 |4 R$ u+ z5 s
; Split on newline (`n)
' G3 V C, H8 {, u4 U; `8 o# Y/ L StringSplit, word_array, full_path, `n8 B" E3 }! k3 l4 [# b+ e
; Take the first element from the array' I, E7 a2 t( p6 a @7 u+ K, ^
full_path = %word_array1%
+ @' \) C$ _4 I* ] ; strip to bare address5 Z/ o4 V, z, O
full_path := RegExReplace(full_path, “地址: “, “”)
! f1 g: }( s% r g ; Just in case – remove all carriage returns (`r)
) F( _8 v: V5 v4 i- T" {9 W StringReplace, full_path, full_path, `r, , all( w {2 I0 z8 G( W* ^/ \7 h
IfInString full_path, \
" r! G; f- c, I9 t$ n+ V9 O {
2 @2 t# j2 `7 Z: @9 G Run, cmd /K cd /D “%full_path%”
/ `: {* A/ e9 B2 } }7 L" q, T2 a) S0 N |/ s/ [
else
4 Z9 ?; z/ M$ ~, p0 \% x2 h {
6 s, h1 @* l. U Run, cmd /K cd /D “C:\ ”, p3 m6 Y* L, c! h
}8 k8 B, |. z* F1 L; s
}/ @$ u! n9 [( T, \4 `7 Y' C9 j- f
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
& S7 B* l8 i7 f: U4 v 这段小代码肯能有两个你需要修改的地方" }1 ~) l1 V& o
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键7 Z M& t5 z$ q+ s+ j
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “5 {2 }1 y+ z9 i
|