此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
8 k0 \, O j5 W+ e 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
1 {; q5 G5 B5 r 方式一:4 ^" k& J6 g3 q& c7 ~% q# {
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,$ l3 @" k9 Z; X( z+ t9 e: d
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
7 w0 O6 J# l( B$ g$ Y HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
$ I* w# X4 z8 E" Y( s' h 方式二:
5 A4 _, H8 X9 ^! G% Y6 H4 D 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
% d8 E, ~& j+ E$ u SetTitleMatchMode RegEx
! R* N' b5 u* w return3 ^4 P7 J: g' d! x, W6 I
; Stuff to do when Windows Explorer is open( X5 s9 s# i7 U5 g P6 G
;
3 d, h3 v/ H9 _' M& @ #IfWinActive ahk_class ExploreWClass|CabinetWClass0 a- w) r" Q3 Q5 v) y& m' p: A
; open ‘cmd’ in the current directory
+ M/ _% {0 Q0 D/ z ;
; Y9 e+ Z+ T$ v7 o #c::: ]) X! C$ r2 c6 w4 s6 c
OpenCmdInCurrent()
0 x" H1 X8 S% r) W1 A! N$ K return, x9 G7 P' e: P- _% d
#IfWinActive8 s+ S& L1 z7 S; Z
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
( H# u3 h! |" u4 y ; Note: expecting to be run when the active window is Explorer.
7 L1 E4 e6 e$ S$ w9 L ;- W& u9 E7 H. w$ t! \- w
OpenCmdInCurrent()
9 v' O8 \% ?$ ]+ ?6 s { Z. I, @* O0 h- D+ m J( {1 J
; This is required to get the full path of the file from the address bar
% t7 g C& g; X4 O, O WinGetText, full_path, A
Y& [; x/ Y+ ^4 F$ K0 I) o% E) v ; Split on newline (`n)
& {/ Q% t: u, `1 T" c1 f StringSplit, word_array, full_path, `n
7 ?3 @( _) n# ` ; Take the first element from the array5 c2 d; W! Q% i
full_path = %word_array1%
) R8 V* Q$ h0 M; n) i! L( G ; strip to bare address
/ q+ F+ [5 U& F full_path := RegExReplace(full_path, “地址: “, “”)
: q6 g- f& i" d, d+ a1 J7 I ; Just in case – remove all carriage returns (`r)+ S) E0 ]1 i/ }; Q* |# y' O
StringReplace, full_path, full_path, `r, , all7 r& ~% f! _' q9 y- m
IfInString full_path, \/ o) c1 P6 u* ]! C0 f
{
7 L- D" f9 E" q Run, cmd /K cd /D “%full_path%”
5 K+ l! g. l& H }
: I& [/ ~% E" [8 \* r/ T5 N else
" k. e6 ^( j% O7 L' t- v! t {/ S/ S) Y- r. u t* L, ~
Run, cmd /K cd /D “C:\ ”! W* O% |: o/ c9 t2 ^+ E4 P
}
$ u* C# S* f v3 M }
5 q' t. B: b, D; T( B( \9 P 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
# A$ c ~) C5 E# C" f 这段小代码肯能有两个你需要修改的地方" U8 f/ A6 `' Z, U. y# C: J3 Y! H
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
6 Q* A6 v# }" V* s# r 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
& |; h5 ^9 ?( S; F; t O6 F- W |