此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
, x2 A4 G5 _* @ W2 r 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 V6 v- ?, n# @. T. _
方式一:
# q& G# p/ F0 X 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
' w! b) s3 A, \: r% `8 D: S 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
3 u" i" d9 X6 {6 v$ Q/ }8 d HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
' J1 A5 E) }! K1 ^0 T9 X 方式二:: G+ @. P; v$ C3 l# J' k
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
8 T* q( [ E4 R9 m6 o7 ?7 a SetTitleMatchMode RegEx
7 C4 ^; F# f2 q! U return
e- G, [2 u0 y0 |% G9 f7 K/ t$ U& o ; Stuff to do when Windows Explorer is open" J% x! V' ?7 D4 R& K) K/ ^9 j
;
; r+ k( s7 z5 \& G, e! J9 z* z #IfWinActive ahk_class ExploreWClass|CabinetWClass2 K. h9 `5 {- y4 U2 l% S
; open ‘cmd’ in the current directory
( ~# t$ A3 ?6 o. ~3 _/ x ;8 _0 S! I* {# K5 m6 j
#c::
' r# J/ v/ i6 }6 G OpenCmdInCurrent()
& U* X C7 [: S) U return1 U0 g/ |" W3 u1 U
#IfWinActive8 B% A6 ?8 y) n) Q: v& R0 F
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
8 `' \2 A) Y: e! {3 Z* s" k1 h ; Note: expecting to be run when the active window is Explorer.
. ~# R+ j% [' g ;
7 D! F1 |$ S. y) _/ ]3 [- X OpenCmdInCurrent()
/ q' E4 D$ p3 @6 P$ K+ k6 h2 t0 ?6 g {; O; t. o% U4 }7 M4 a6 y
; This is required to get the full path of the file from the address bar
7 d5 z8 X. [6 ^7 K; a/ B2 | WinGetText, full_path, A+ A/ m9 m' v! s; N' y
; Split on newline (`n)
, L: ^/ s$ [( J3 e M Y3 W StringSplit, word_array, full_path, `n
2 x* W, v5 v1 O, A9 @# @1 q ; Take the first element from the array
( o' t. w# Z4 x3 {8 z) l full_path = %word_array1%& b$ u# R! t) a" V w# a4 Q# G+ `
; strip to bare address
) `: I" ~4 K# l% e- v) D full_path := RegExReplace(full_path, “地址: “, “”)
* ?/ |: }; j+ w; ~ ; Just in case – remove all carriage returns (`r)" W& h- I" P5 x. b t; X
StringReplace, full_path, full_path, `r, , all
/ a6 Y3 Z& T1 A" t IfInString full_path, \% z5 H3 e* Z) G4 U8 G6 _3 R
{ V/ f8 k& [# z. P7 K+ T0 f( v
Run, cmd /K cd /D “%full_path%”8 V$ E! u! H$ ~& Q
}4 d' f/ L* y p" t: R, N Y
else
% r Z4 v* f0 q' ~/ E1 v {$ S( o5 _; d( W: T& T
Run, cmd /K cd /D “C:\ ”
! U" G0 u- ^6 |! |' x }& M" Z2 T9 D& S) r- Q" }: b; r2 K
}
/ s; c- X$ Z4 q# [% v 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。$ U) e: z6 C- c/ S0 F8 s- _4 C
这段小代码肯能有两个你需要修改的地方
+ G- J7 J" d1 W 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键: S1 I6 `3 T4 p9 M
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
# X# H- S# x* k6 E& z. v |