此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。& u3 s# V1 }# k' y
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
( [4 x9 F; ~, f3 e 方式一:
5 N& T2 @: t1 v, h; ] 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
" z- W5 t4 r5 D5 H; B* ` 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和% q/ J+ \4 S0 @' V2 b
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
D/ e. O' v0 G+ Z# l: l! { 方式二:1 y/ f) ` U: _
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
, m4 {* [6 I. g. L1 p+ c SetTitleMatchMode RegEx) T. i1 e8 q2 I# ^9 d" d1 q3 e
return
: Z+ P( ^8 @& L ; Stuff to do when Windows Explorer is open
% @: d* J3 w8 t/ P% e ;) l+ F% ~3 w; D* w3 W+ E5 e; N) `
#IfWinActive ahk_class ExploreWClass|CabinetWClass
4 L2 A1 `8 v3 ~6 D ; open ‘cmd’ in the current directory0 l2 _1 l6 K4 M& Z
;
6 | \! y) k4 ~) I. ?/ { #c::" R; } i6 k$ {1 g$ v' T
OpenCmdInCurrent(). P, V) a% ?7 r, V! ?
return+ b& q4 k6 Q* h; q0 A* l; U
#IfWinActive
5 x% r$ ^: Q) l# U2 k) ~ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
Q& E- k0 K1 _+ b$ a" i- n3 H7 Y ; Note: expecting to be run when the active window is Explorer.# Y1 Y* ?& t% q2 j" j- t
;
* h8 H& y; F8 x) k2 P2 u3 ~ OpenCmdInCurrent(), ]; G$ E5 u0 B% h ]
{
/ R* e4 o) F4 |3 M7 P- f ; This is required to get the full path of the file from the address bar% E- e9 ~. B$ u& h
WinGetText, full_path, A3 U( ]8 a3 |: f4 K0 I1 i8 ^
; Split on newline (`n)& u/ O% w( k G1 _
StringSplit, word_array, full_path, `n8 f8 n; K4 O& r! `
; Take the first element from the array% {3 B4 q A0 b; [
full_path = %word_array1%' {4 r: {" g3 r5 O/ p
; strip to bare address. {1 x$ [, ~# q
full_path := RegExReplace(full_path, “地址: “, “”)( x9 ]+ H1 N" O* J
; Just in case – remove all carriage returns (`r)% b3 b) ]) h; h* ]+ z; ~
StringReplace, full_path, full_path, `r, , all/ ~/ M, C& R, `6 @
IfInString full_path, \% P# L7 i5 a- ?% A' j2 Y2 ^. A
{
5 ?1 a8 e# X( Z: @, W Run, cmd /K cd /D “%full_path%”
- ^: N! t0 e7 R8 A: i1 b6 k m }9 r3 y) |9 i- O9 e* k
else
. r: ~0 E, c4 D1 u, N! a {
! V' p- ^( }, F) u' [* M- e Run, cmd /K cd /D “C:\ ”
+ t, k6 K. @* F2 a }/ ]9 M5 S) B6 V2 K
}- F! U$ ?( k3 i% k2 W7 R/ F! y
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。; S' q7 r$ _$ j5 ^5 ]+ q
这段小代码肯能有两个你需要修改的地方
& O4 z* h; Q0 \' `$ }# S 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键# Y6 T+ z {4 l) U
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
) C6 B6 K ]' ?5 p! `4 T |