此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。& O8 J. v7 Y5 j1 w1 Q: O
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 y. Y( w8 q; w' E 方式一:+ n6 L4 A' Q6 R% m1 n& i
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,# H( a# r i2 w7 f1 f" {1 l! T
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
1 l, ~. s/ M# o+ a/ F1 [, o* L0 | HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。) `- o$ b+ z( _( U' K7 }& z
方式二:
3 [' F4 Z) y% R) i1 Q; ~2 L8 c 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:& J( F- z; O) q I
SetTitleMatchMode RegEx
- m$ i! _" }5 ?1 ^ return
/ l! y! d% \7 B9 Y2 @ ; Stuff to do when Windows Explorer is open
0 @! f5 _: q' X" |9 \8 v- m ;
$ M5 B+ ~' o5 x/ b* K4 h/ U0 n #IfWinActive ahk_class ExploreWClass|CabinetWClass4 ~/ e8 ^/ b8 o
; open ‘cmd’ in the current directory
; [# P! o6 E- y$ d* h) u ;$ s% V% y7 ^+ g( ]
#c::3 Q: R9 l1 |" T; {9 _" S
OpenCmdInCurrent()
8 `$ A) ?8 K/ z, c return7 X. j5 n/ x, `( g
#IfWinActive. o7 p( b" {- b j. p4 `7 \! R
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
" _. K7 L" Q! b" r9 d b ; Note: expecting to be run when the active window is Explorer.1 [( e! _4 ?- a4 E8 y, |
;1 o$ E R1 }' `5 F. I
OpenCmdInCurrent()
- l& Q1 P' `5 a, q6 { {0 ~6 G8 x" x; n7 m& x" }
; This is required to get the full path of the file from the address bar& ]/ F. Z" v+ Y8 q4 b0 i
WinGetText, full_path, A! o, n1 F ]. ]/ ^
; Split on newline (`n)
% i8 Y1 H5 y% z* ^2 w StringSplit, word_array, full_path, `n
4 L" v# K; a" b7 C: G6 s/ t ; Take the first element from the array* ?6 ]# ~) y, e
full_path = %word_array1%9 N8 h0 n i4 R- D. F5 x R
; strip to bare address
4 m' j0 x( a, g% Q' Q" x2 } full_path := RegExReplace(full_path, “地址: “, “”)+ z2 Y( Q" `6 [- R
; Just in case – remove all carriage returns (`r)# n) i% A! f9 |6 ~; _
StringReplace, full_path, full_path, `r, , all) x! W5 P$ ]* [! N: e/ o9 \
IfInString full_path, \
, j! k* y& @5 r' p8 I {
2 M% S- {3 M) a% Q) t Run, cmd /K cd /D “%full_path%”
* T6 s, T, X+ M, ?! N5 }1 _ }4 I) u6 V8 W" g% F. h& Q& `
else
}; \6 l" J& Y/ P# K% D {
0 ^! r4 C: A$ }, F* h Run, cmd /K cd /D “C:\ ”
# g4 m. O6 h4 R- c g0 V4 @ }8 N& N; G) k' J% U
}& B4 M$ n. q8 C0 A
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
/ h/ @" q: D* ^" D2 z1 r 这段小代码肯能有两个你需要修改的地方: E6 Q- [1 L% g: v% s
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键" |9 t9 N. F0 a" v- M1 ?8 @1 K
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
9 {' l! I- [$ f8 i8 Z |