此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
7 ?7 c9 A! [! h5 g9 U( h; c, } 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
& F& { a" i+ b; a- ^) o; i 方式一:
" K# I1 K% P& f, K1 P1 j; s 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
2 H5 U T+ Z( s' g/ ]) O( _ 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和9 R9 D! P: l4 y: i: {9 U/ k
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
' L" x. j# I$ W 方式二: o+ Q. K/ \6 l" h# N, V1 }! g
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
3 n; m' ~0 H, N SetTitleMatchMode RegEx$ a. L; t# q; O2 t! V
return
% n, B6 Q, {" ]7 Q* k3 V; D ; Stuff to do when Windows Explorer is open% h; M* ?& D5 e7 e
;
' @. X1 M+ K! t. m #IfWinActive ahk_class ExploreWClass|CabinetWClass: b2 R( Z$ t9 V, F8 B- _; N% r
; open ‘cmd’ in the current directory
$ i3 i( j6 m5 o ;
7 u& Z( l2 E) b; B4 s# [: A" G #c::3 M; P% l9 ?6 V- t0 T. M( t8 g
OpenCmdInCurrent()4 o5 e9 ^# w# W" {
return
( k* J. R4 S1 u #IfWinActive* C! }6 _$ z( u. m/ d
; Opens the command shell ‘cmd’ in the directory browsed in Explorer./ d8 ~; S% v U6 X2 O0 O
; Note: expecting to be run when the active window is Explorer.% h8 W5 ]4 r9 }/ X% ~' G( x4 R
;$ [" y' c( V# s* s: F
OpenCmdInCurrent()! N- w6 J+ q5 `. ^' d- R
{
- p* \. h) @: B/ S- h7 a. O! k ; This is required to get the full path of the file from the address bar
" e1 T! v8 ]* s# e* i4 _, J( ^ WinGetText, full_path, A
8 l2 |1 t5 n2 e ]) O( ]7 s# D ; Split on newline (`n)
! v8 c$ L* H" u+ W StringSplit, word_array, full_path, `n, E/ Z# A. p4 R/ H# l
; Take the first element from the array
2 F5 O+ ` D6 v full_path = %word_array1%
) G& G3 G2 [! H3 U$ X5 F ; strip to bare address
% ~& B/ r0 n* u full_path := RegExReplace(full_path, “地址: “, “”); _" m1 A0 ?& _" W r
; Just in case – remove all carriage returns (`r)/ ~9 U0 D. [' Q ^+ ]
StringReplace, full_path, full_path, `r, , all
0 X: @% W. \% o3 a7 W* y IfInString full_path, \9 f* w; S6 u, \3 J& a
{
0 V2 d' Q; F, t! O: x: D$ e. \/ Q+ _ Run, cmd /K cd /D “%full_path%”* t8 z! `; c) \, x' S4 t1 X1 q
}
# k5 Z8 `$ O# l( O) L8 G. n else2 G2 o/ K9 J6 ]6 Z3 h
{
4 A, u! u* P% N n$ p Run, cmd /K cd /D “C:\ ”) d" d2 k f0 L
}8 ^, q5 r& L: ^+ J) ]- B
}' g3 \& n9 E3 P& b
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
) @- Y% { b C' Y+ V 这段小代码肯能有两个你需要修改的地方5 y" p8 w, a% `. Z, E$ q! M4 ?
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键* O" V6 F4 g8 ^2 L# I# z
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
9 X7 _6 u/ C8 K |