此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。5 j1 m9 x& b( z
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
5 f' o" Y, L5 N; b# \# s 方式一:- `, ^' K$ K4 {
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
: [$ K- e1 z- l 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
% T: ^8 |: {1 d; B4 F n HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。5 o Q. ^0 g2 q6 ^
方式二:6 b) g8 z- T+ j" _- U) W
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
, j* |& d7 m: H$ ]- q x SetTitleMatchMode RegEx
& Z+ D- ^7 N8 ]- ], l+ | return
: y p$ D6 ^1 z7 S& E+ B; r; L ; Stuff to do when Windows Explorer is open& _! E1 d/ \6 {3 H. ^! L, I
;9 z# X( [: T1 v' h
#IfWinActive ahk_class ExploreWClass|CabinetWClass( C6 w8 G' ]& G; h) [
; open ‘cmd’ in the current directory
4 K: k0 x3 J$ H% a( U, Y ;( r- O8 d0 T6 Y W* O1 _
#c::" y' E* ?0 Z% V
OpenCmdInCurrent()9 o8 |7 z0 D0 `! f
return
& X4 Y* e g3 `" L' W5 T #IfWinActive
# r. M7 H& \5 j# k: X1 B ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
, ^9 f" d3 O. i8 j8 X& ] ; Note: expecting to be run when the active window is Explorer.3 z% k- h' u- A! f" E- t
;
! M; f, _8 V- w9 X/ M. f$ T; [: H OpenCmdInCurrent()8 M4 `- y+ C6 V: l* R1 c
{: C4 K/ M6 `1 X
; This is required to get the full path of the file from the address bar
: {# A& k" i* N WinGetText, full_path, A# u, [- O- M, Y0 _! R/ g% M& E
; Split on newline (`n)
0 t9 H* a# F- g StringSplit, word_array, full_path, `n
9 N/ b* |: l, j) Z3 r, Y ; Take the first element from the array
+ D. Y2 t3 L% W& n2 A+ D" J full_path = %word_array1%; J+ q& d7 E9 ~2 _% s
; strip to bare address
! J8 Z) j" [0 ^* b7 w) H; V3 r full_path := RegExReplace(full_path, “地址: “, “”)
5 R3 h" d. q- m) g8 B ; Just in case – remove all carriage returns (`r)3 y$ E; H( Y) Q2 Y4 ?1 a: O8 F. {* N
StringReplace, full_path, full_path, `r, , all
9 s C0 \, A+ z5 H! g& V- K2 R IfInString full_path, \
8 H7 _3 z* r( U% Z( u {. B$ x- j; J x0 e4 g1 i
Run, cmd /K cd /D “%full_path%”9 E( Z' b( t |+ k& k" `2 i
}7 t8 K0 b+ F# z9 p
else; V& V. P* m) C/ K& r3 M' r8 n) i
{
9 ?! \% ]( p& {. O Run, cmd /K cd /D “C:\ ”
; j8 T, v1 L% E" @8 g4 _ N# R }
4 }$ l' \% v# ?( S$ y8 I }9 o# e7 k1 q: |! {$ k4 A9 [& |
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
- q* J4 u% _9 [+ p3 P' k! I$ u 这段小代码肯能有两个你需要修改的地方& j' w+ }/ M2 M3 V2 ^
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
& }5 i: R, ?- R( M 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “, u- J. S/ q0 D9 {
|