此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。2 B0 F, m9 z* B* Y
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。- Y7 z% p* [! h" o% }- n; x
方式一:
0 W& g$ W, m& n/ F: Z 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,1 L# S i( f/ k/ d- }! ]
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和- Q/ O9 B/ M8 s3 d/ F& N
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。# w! ~2 {4 t7 Q3 E! b+ b* h4 c
方式二:, o* v. z1 i; g6 A
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:- f& x$ M$ U: K& S3 u$ b( z9 g- {
SetTitleMatchMode RegEx
" X1 S8 F$ f( a+ Q+ {& c) @ return7 g7 X& |9 t1 y0 W, i. @
; Stuff to do when Windows Explorer is open
2 [) l# L! m6 F ;
( H% ]$ m' R/ @, N7 Q* D3 r- | #IfWinActive ahk_class ExploreWClass|CabinetWClass2 ?+ r0 P; g" f' g2 Z7 _
; open ‘cmd’ in the current directory9 \3 v% D8 j5 l; r
;
; L5 @3 x4 t! P3 A# v5 y' g1 ]) | #c::
: ]8 z4 g. |9 D, ?. L OpenCmdInCurrent()4 M+ p! }; @1 v0 I/ ^# v8 l
return: y2 P2 k: u H/ I4 _2 o
#IfWinActive
9 G! m) e a- F& k3 z ]+ ` ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
4 u, ]1 c9 ]; Y5 M) p( T5 D ; Note: expecting to be run when the active window is Explorer.3 g6 \8 }% ]0 f' Y: V
;
% B }/ |7 }$ o' E! x3 C OpenCmdInCurrent()
0 h: v" D4 j/ I2 B6 k' Z" y- } {
( [0 P, \" h/ u* L5 q, B ; This is required to get the full path of the file from the address bar
& L4 u, m7 e8 E: G; c/ x' G+ h' S7 m WinGetText, full_path, A( A; Y, h3 p5 E! S) p! D
; Split on newline (`n)
# B: v/ N! P; _; p: ` StringSplit, word_array, full_path, `n" R. Z$ d3 E$ U# ~
; Take the first element from the array( j8 Z9 E! b* R4 u. V8 i, V
full_path = %word_array1%+ k/ `; M& O/ w* q8 n' ~6 M' `
; strip to bare address
+ w. ?$ W& j( L( b9 v3 a' Z full_path := RegExReplace(full_path, “地址: “, “”)9 o" p% `. O; A/ U) K! r
; Just in case – remove all carriage returns (`r); g5 Z8 d+ `$ ]+ [" @
StringReplace, full_path, full_path, `r, , all' F% X% T& `. ]4 ]& Q2 ]! z1 v
IfInString full_path, \& q. x9 e5 m- T1 T$ ~6 D
{7 L4 l( I: n: C* u( o( X
Run, cmd /K cd /D “%full_path%”
8 t; t3 E8 I+ L& ~7 S V- I }) a; f) Y6 U) G; N
else
* |1 N( R% z- l& `* c- V0 t- j* v7 p {, F# c: h9 ]; l1 E4 |
Run, cmd /K cd /D “C:\ ”' p& {! A+ h$ q' I
}! H7 f/ h6 W/ }
}
" Z: r" S; _0 V. @4 d& Y 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。" s; m" P+ O! [, ]
这段小代码肯能有两个你需要修改的地方; s+ {$ y8 _% \' E4 k
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
# ]& D" @- H+ X: l/ L( `% f 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
5 A% ?: ^& @8 J' P, Q8 `1 t |