此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。6 l; ~- x7 S% }! W J
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
8 v% d! D8 Y: k8 Q3 }% Q9 [ 方式一:
4 s' ]) t$ h$ K2 d 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,, H! p; t) L" c( U4 M+ [! X
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
$ [4 z, A1 C- S/ n3 e8 g HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
7 E7 j2 Z. q0 Y1 {, [& L 方式二:
$ e" t7 c6 I8 E N 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
$ Q) b3 s- {& ^' Y$ S5 W SetTitleMatchMode RegEx
, x+ M2 V; ~7 L( y. Q return
" P! s; ?% Q: J' _" N: S ; Stuff to do when Windows Explorer is open
; n' P+ q$ z a/ _2 Q# W( k5 u ;, N. k3 j" N0 r' I4 t$ N
#IfWinActive ahk_class ExploreWClass|CabinetWClass# ~% \- p# z! o8 @- L& r
; open ‘cmd’ in the current directory' U) |1 K9 X, B0 \2 x G* q
;- w! T4 \" {$ }: L, `
#c::
: T& y/ P; }0 S2 m OpenCmdInCurrent()
/ |/ a; c3 \, m4 y, C- N3 Z return
: p" s, h' n- Z" g #IfWinActive9 p$ ^8 s1 s/ B4 X- \
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.8 I0 W% O) p$ I& |1 r+ e
; Note: expecting to be run when the active window is Explorer.
8 ^* y% S7 y8 M/ L- ?+ e ;
4 v! k8 O* d' N& Z! Q OpenCmdInCurrent()) E( S; J% l4 Y3 _
{
t+ a' {$ A* q8 [3 {0 I4 _ ; This is required to get the full path of the file from the address bar
% W- E6 S2 T" n: N2 G: w WinGetText, full_path, A( q8 E, W6 z7 o1 ?- u
; Split on newline (`n)
0 {" |# t( |/ g `7 H: M. c _# ^8 q StringSplit, word_array, full_path, `n
3 K# P7 O* w/ T5 a. E2 v ; Take the first element from the array7 m- C. d+ y+ q( \: p1 z
full_path = %word_array1%' S7 C, k W: [) g: }; a2 C. H- l0 F
; strip to bare address
1 B- d- \5 n g. v3 ], V. ~ full_path := RegExReplace(full_path, “地址: “, “”)
4 z3 G+ ^5 q, `6 v& e) f) a ; Just in case – remove all carriage returns (`r)
1 i. x2 M. v4 t StringReplace, full_path, full_path, `r, , all
: B( D4 V7 ]8 o% I# y: F IfInString full_path, \
, f5 W& r* U: R {& h: z0 n3 j# [
Run, cmd /K cd /D “%full_path%”& F; _0 u0 k6 @( P
}- M3 z9 m+ s/ P7 {5 I; ?6 M
else% v$ @2 G) B. g; R; O: ^! t
{
5 j0 g6 N3 F" Y8 X: t$ L Run, cmd /K cd /D “C:\ ”, R5 L) p. |8 v) e. v
}
/ W6 G! U2 x2 u# e }- S! j6 c% o* _% w# W1 c
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。" n7 L; v6 k: V! H ]
这段小代码肯能有两个你需要修改的地方
3 J- S9 J; J/ X7 v 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键2 Z2 F& a* K4 F/ u9 N) f
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
( Z( k. l; S, R |