此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。: ]( B9 [" W- z
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。. [, Q1 t+ P' }6 F! h+ f5 C$ g2 [
方式一:. w* l& Q0 P* r
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,5 s( y f e& t4 c) l& A
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和# W! m' h+ Z9 [6 d( ?; y1 v" U+ \
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。9 n. s% ]$ w* T! Q, K
方式二: T3 H6 c+ J" |3 e# U# t/ P
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
. ]' y, |6 z# h: x8 ` SetTitleMatchMode RegEx
: X q; | `; }/ _- k( S2 B, Q return: _+ b) ^/ ]5 Q0 c0 P k1 ?
; Stuff to do when Windows Explorer is open$ H/ D0 P- l2 p4 @* G
;: E; m" s9 ?3 T9 F
#IfWinActive ahk_class ExploreWClass|CabinetWClass5 Q; W+ G7 _ Z7 F' h' Q
; open ‘cmd’ in the current directory5 A5 L8 M9 ~# b0 A u
;
. c1 M) ~' e. F- | #c::1 L5 H$ b3 Q8 U/ H5 k
OpenCmdInCurrent()
0 }4 U1 ^) ~& n. N return
- y6 E6 j' f! b/ ` f #IfWinActive. i- E Z( P) h+ \& ^; F9 x
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
/ R- h/ J: F$ P$ H8 E ; Note: expecting to be run when the active window is Explorer.$ x6 C0 o" |+ c
;
8 N; R% h) `4 q, N! |( y OpenCmdInCurrent()
; f ~5 f1 ]0 z# e3 j2 V7 W {
1 g5 T5 {* F! U/ B8 @% |, V& m ; This is required to get the full path of the file from the address bar1 P8 A/ R; u9 W7 }! \
WinGetText, full_path, A
. Q8 \5 ~. u5 C+ F ; Split on newline (`n); o6 P. `( s/ w
StringSplit, word_array, full_path, `n
/ g8 h/ p; _ h i$ T ; Take the first element from the array
/ I* g. O# r- ]% j0 C full_path = %word_array1%
- t9 \1 w. P# n4 ]) L ; strip to bare address- @2 M* U! z/ d7 a/ t6 P& C5 o
full_path := RegExReplace(full_path, “地址: “, “”)
6 b- Y S6 t9 e1 o, r$ H0 @ ; Just in case – remove all carriage returns (`r)
; ?5 {, I) S; Z3 @* u0 t StringReplace, full_path, full_path, `r, , all5 S6 v: Y* c# ]1 i8 N9 ^
IfInString full_path, \
x' Q9 \* v6 {( b+ @3 H& ^: e {3 E+ }2 ?# c/ t
Run, cmd /K cd /D “%full_path%” U# ^) g& g& j {0 d
}
* o' Y9 P3 ], W E else
4 s% r# ^, J: q$ M8 ^$ f {- ^- v7 ?" Z. t6 Q: S, I
Run, cmd /K cd /D “C:\ ” D! |0 ?& P$ ^% O8 g
}
% p+ P; H* P- s' P, g6 d* D( ^+ c }, x4 h( z- R. W: x9 `
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
5 M9 [. a5 K1 D' Y6 m, S& l! Z) s( S 这段小代码肯能有两个你需要修改的地方
. }7 [' ]; j- }( r9 C! Q 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键4 p& x" j j% _! w4 o
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “8 f( d" d* S: J1 |. |1 ?
|