此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。' d( ], |1 o+ m9 ^4 ^# l5 P
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。. ~1 \- Q0 V9 |
方式一:. E) {7 G" Q6 X1 a0 \" ?
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
% A5 F( P: f) R6 a8 P9 b2 v7 U 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
7 q" ?8 X2 G; o* L( o5 I; Y* m: H HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! Y' p. `1 [) F# j/ Y0 U7 f2 V) A
方式二:
C& @+ U2 l2 \; y) p 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
! W& Q$ n/ N) `0 w SetTitleMatchMode RegEx
" j! Q4 u z7 M4 O; z. V7 D! Z0 } return
7 T+ r. }0 ~1 c9 N( y! t ; Stuff to do when Windows Explorer is open
9 i$ r& N& ]1 ~4 N, E ;$ ]; R" G4 v! }
#IfWinActive ahk_class ExploreWClass|CabinetWClass
" x6 Q5 n1 c$ T6 y/ {4 O ; open ‘cmd’ in the current directory( w# M2 d/ d; M Q- L
;
4 b, g6 Z' ^! L #c::
) b6 M4 m# y$ x! n6 R OpenCmdInCurrent()
# q: ~8 X$ P$ R& E( I return
# V1 K. S; v0 A+ u& a6 u #IfWinActive, L) D7 f! j3 Q, ~7 w
; Opens the command shell ‘cmd’ in the directory browsed in Explorer./ \$ ^0 j( [/ y. f+ t
; Note: expecting to be run when the active window is Explorer.
' Y, H, a; m `3 E8 R+ a ;9 p4 o8 \; _. Y0 M
OpenCmdInCurrent()
: R7 V5 t3 [' K# h! m: p* c$ P% J {
+ z% N; e- n% E `, J ; This is required to get the full path of the file from the address bar9 |4 E2 F, W/ a- V4 K. A1 {3 P
WinGetText, full_path, A
& p0 s7 J6 `, L ; Split on newline (`n)6 i: |- x/ P) i% f6 x
StringSplit, word_array, full_path, `n
, o- N+ L2 P( _" j0 L/ Y ; Take the first element from the array
0 x) C7 O/ Z: E# {! b full_path = %word_array1%
+ K- @9 G3 n. M6 }2 G4 t- V ; strip to bare address2 X7 t9 d1 ]* k, G6 g9 q- |
full_path := RegExReplace(full_path, “地址: “, “”)
% P/ k* z$ E! T# N2 G; H2 v& M ; Just in case – remove all carriage returns (`r)
0 `: G" [" Y. e$ J" X- ~2 m StringReplace, full_path, full_path, `r, , all
7 M G Z: x+ n IfInString full_path, \1 u v1 @8 V: n4 I
{
7 C* i* j+ @, J. A, K; b0 r Run, cmd /K cd /D “%full_path%”3 ]* I9 b- l3 W9 `; t+ O; @, o
}- o6 T- T- q. s7 J4 S
else
L! L+ o. z3 s. Q {
; }3 m$ Y; M! M, e2 }7 V4 o4 U Run, cmd /K cd /D “C:\ ”' U) m r% Q6 R2 c1 M. j# a& g. I
}
" y: |% y2 F: {. w }& V/ G( |2 L' P9 W; [+ ~# G- U! E
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
2 X0 [9 a6 P/ [% K+ r, i 这段小代码肯能有两个你需要修改的地方0 s# X0 o( o/ E3 j- Y9 J
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键# S$ s( w q, u
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “; z5 m" n' e/ w- R" [9 G% r% U
|