此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
W& K. X9 ], E: W 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
4 W9 s: M0 F/ J7 \; h 方式一:: G) H) O+ I+ }. e7 g6 f
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,/ Z G/ d G8 z; _
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
* B- z- t& y$ u/ p O HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。5 L1 Q; U( u3 O/ W2 C8 h4 O
方式二:
- S9 o4 R, S9 }9 ]8 _2 B 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
# R+ d( l& A. R& J$ ^: [6 Q4 G SetTitleMatchMode RegEx
, I7 f+ y% p$ V* m2 B+ M4 n return
. {5 z4 t; o4 b% t) S ; Stuff to do when Windows Explorer is open" P+ k3 v8 F* [2 `' p* L
;
. f8 D2 P* Z( N) Y #IfWinActive ahk_class ExploreWClass|CabinetWClass0 F5 [! ]9 _3 I* t9 M
; open ‘cmd’ in the current directory
& h d/ I, |& p/ J# l( j4 B ;
; R: Z) R/ R! o- B! ? #c::0 w( ]( l4 J. k3 I$ K
OpenCmdInCurrent()
5 r3 F: }( e, P7 O& d+ e return
* Y% |$ r+ }9 | n& Z1 M! j #IfWinActive. [; L: G3 B# E4 {. Q3 [
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.& i3 t- P( w2 ]" z2 O( V6 N
; Note: expecting to be run when the active window is Explorer.) J+ a( I; T1 E
;8 d5 r, A$ H' a) ]. C9 B; X/ h
OpenCmdInCurrent()1 d' [: @2 o$ v+ |% X
{3 H# S- O D& H& N& V! h% |, x1 I
; This is required to get the full path of the file from the address bar
/ S. r7 Y: Z! @1 C2 X5 O0 l! z8 K Z( k WinGetText, full_path, A
- o& \3 H/ A% P/ h H! u0 d% j: z ; Split on newline (`n)1 r- ^6 C3 n. r/ O; ^3 J
StringSplit, word_array, full_path, `n8 I) a! ]" i! \. N
; Take the first element from the array
! S% y1 w8 K( ]9 [2 V, t2 b8 l full_path = %word_array1%
& i/ @4 t+ w4 t! ]0 @. K ; strip to bare address
6 n0 O- m8 @& I0 x- R full_path := RegExReplace(full_path, “地址: “, “”)* j2 U( A) g+ M: Y7 Q
; Just in case – remove all carriage returns (`r): h: f6 _5 |- P2 L6 y( E6 ]& s6 o0 B: W
StringReplace, full_path, full_path, `r, , all- e4 j, ?& a/ \) @! C" r5 V \0 Y
IfInString full_path, \
* g$ w2 g) I v {/ x, y* t) M8 h9 @ g- D- {& D* y& I
Run, cmd /K cd /D “%full_path%”5 r' X/ @0 @: j! i% K
}5 Z$ q, B4 A( Y; Z5 L: t. C5 J( H
else
- K8 R5 ]; I4 T5 I! E* G/ w) U% D& O {
. k" i9 A' \( d/ ?7 W1 a* Y Run, cmd /K cd /D “C:\ ”
' c; e0 q: r F' f& c' G }
4 @+ v$ Z" e2 o1 A }- ]( i3 J4 C0 h/ A& N1 ^$ ?
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。" {6 L, a, C- G: e9 M* A- K9 P9 X5 `
这段小代码肯能有两个你需要修改的地方: s" n/ q5 m4 c3 b' j* z: ~0 K
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
- ]! r* C. ^2 ~8 ^0 V 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “% A. [$ A. Y- m- H
|