此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。- |3 x: N4 t% c/ X# E" R
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
. T+ M; t9 a0 H 方式一:4 g+ f6 h# `! k
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
' M! H% l1 s! `" j- u 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和( C& h5 G- E8 j$ D/ y* B
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
+ w" O. B! l! H) e4 Y 方式二:, x( s6 r8 V8 t @3 A
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:7 {! j) Z) y. | }( v g1 `8 Z9 q- d
SetTitleMatchMode RegEx+ O& w: i; r5 F/ }
return3 K% t7 @2 ?" ]) O6 I, h5 d, M
; Stuff to do when Windows Explorer is open
. w, z! Q: B5 k0 o( u. ] ;7 I5 }2 p* ^/ j! d3 l/ L) Q
#IfWinActive ahk_class ExploreWClass|CabinetWClass
6 T& f1 _! x; y" e! [; E& e# ? ; open ‘cmd’ in the current directory2 G9 v3 q3 { m9 M- f) ^
;& b; o6 \2 @8 {( E
#c::
" p1 Y7 b, w# k4 K1 [; o( _ OpenCmdInCurrent()
" U2 i0 s C3 h9 N3 I8 z) W% M return
3 m3 V! ^; E. |" r3 X/ o% c #IfWinActive
! y2 K8 O' A5 d; j; _ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
5 r9 f5 p4 }! B/ w ; Note: expecting to be run when the active window is Explorer.: l" ?) g2 Y! b. s; T$ K
;8 O1 D0 p) w7 W2 z+ P; r0 u
OpenCmdInCurrent(): a& }, l5 s5 V7 d0 j
{3 |; {1 ~/ T& b6 d/ ^0 P- n
; This is required to get the full path of the file from the address bar& Q. B( P+ Q+ V7 x' Y: {1 o
WinGetText, full_path, A
2 s! D' j; B. N6 n ; Split on newline (`n)
/ Z# B- W% T" A# ], [ StringSplit, word_array, full_path, `n
I0 [* f2 h: ^2 c: `( W ; Take the first element from the array) x. b5 \6 A1 d' F. m$ t
full_path = %word_array1%
, k8 ~: C$ x/ Q ; strip to bare address- a; G9 |5 U# N# M% O4 b6 e) b
full_path := RegExReplace(full_path, “地址: “, “”)- s# ]8 X( A9 q- q% \
; Just in case – remove all carriage returns (`r)# m# ^ J" r" \) }" V& R
StringReplace, full_path, full_path, `r, , all$ M( {& P. }1 s0 k! h2 \; M
IfInString full_path, \1 q' i. _% g. Q
{; W9 f% L) k z
Run, cmd /K cd /D “%full_path%”
: }/ k0 D4 v' ]& z) Y }
( a7 i( R; k8 Z! [* d else. ~! o' l9 [# t( C
{
0 i [5 I O" k0 K Run, cmd /K cd /D “C:\ ”1 }* Z( E7 p, q$ _* _& s. ~0 A
}
7 Y) e. C. ?* z }
4 S6 n v: p% K 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。* ` S, \) u0 [$ T! W5 x F0 Z/ N
这段小代码肯能有两个你需要修改的地方' {* X0 o4 H3 e" _. @1 c
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键* W+ v. D. }( W9 {5 l
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
+ M5 G( U! {, @* u4 y: `3 R( q |