此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。/ v( }# G$ n8 m' ^" `8 |! d
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
$ S1 W' d/ G6 _8 U 方式一:
$ q+ Y2 L" o; W/ X: H3 S 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,3 I0 n- S; @9 z3 {5 H8 y4 J1 g1 A
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和) ]+ {6 s0 ]) {7 I4 e( X2 S/ L
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
, r( m. b8 W2 S0 G 方式二:2 K' @# r9 @+ M
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
: X0 r; O. Q( r, u# R& ~+ ~3 F SetTitleMatchMode RegEx0 E7 K8 E% L: \2 S
return- _9 i) f2 @ P+ _8 K
; Stuff to do when Windows Explorer is open
# d2 f ]# Q( \$ {+ c ;
+ S( u$ X/ ?( e- r0 |& ^7 ]$ Z #IfWinActive ahk_class ExploreWClass|CabinetWClass- J+ f, i- [6 y) _$ R$ }
; open ‘cmd’ in the current directory
6 q$ P: A$ h0 j. j6 L" F ;$ m6 P" n( Q0 i6 m4 W
#c::
! T& Z' M% S' E OpenCmdInCurrent()
% j! _: q5 B( j0 u! J9 R: T, |% {3 ^; _ return" e/ a5 v# T. m5 ?" [5 t5 L' i
#IfWinActive
) V0 r% I: Q4 N% |2 \$ K7 d ; Opens the command shell ‘cmd’ in the directory browsed in Explorer./ T+ x$ f B) z1 q9 M% f' d
; Note: expecting to be run when the active window is Explorer.
' ]: G) A% X& P; X% C ;# n1 Z5 c+ S: i8 ^
OpenCmdInCurrent()
' R2 F, h, d$ z2 ]; H/ P- H6 W, K {
( y3 q& L2 o3 M! \0 i2 r ; This is required to get the full path of the file from the address bar
" u/ n- `# o1 c: m' Y' P8 g WinGetText, full_path, A% g: s! c6 T5 _
; Split on newline (`n)
1 p8 @; T0 y4 x9 k# D5 O StringSplit, word_array, full_path, `n
. d7 q* d" O4 d( e. u- ]2 o ; Take the first element from the array$ _! E% F5 u k( s4 ~' z6 ]$ x; K' o5 C
full_path = %word_array1%
- z7 r1 X6 U( `9 s E( H ; strip to bare address
/ r3 `! K! W/ T& Z+ ?( Y full_path := RegExReplace(full_path, “地址: “, “”)# |/ [: Y" E% A0 }. @# K
; Just in case – remove all carriage returns (`r)
- J' M/ {3 A. v: A3 {. z( F StringReplace, full_path, full_path, `r, , all
5 m9 [! T; I: J( ^2 F IfInString full_path, \. @$ {7 ]9 q3 X. h6 s* F J T% Q
{2 h- Y. R, a* Y+ h( K
Run, cmd /K cd /D “%full_path%”
! l1 W3 _; v4 G' e1 P2 Z5 ? }! E1 a( W- m- f: q* h- f* l
else- v' T0 A+ C1 H2 v7 H* a% J
{
- F4 Y9 q& d Z) S Run, cmd /K cd /D “C:\ ”
: g: K! s& n* ~! | }
0 `( c+ ?" w, P } e! \" v1 I6 i+ x" A; Z
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。4 u; F5 @7 S5 i8 N8 m2 ?" u
这段小代码肯能有两个你需要修改的地方- M# @; c1 T, _( Y
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
! m! A3 B& B+ l+ u$ }+ j 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
+ ]8 C9 w' Z* @; Y0 n1 }3 B1 {. l |