此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。# M1 y G! K( `5 T
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
1 }) o2 C. q+ [6 Y9 S' A( ]% f 方式一:7 V8 ^7 a+ h. t4 X0 v2 z: e
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
0 t5 T$ `) {% V2 \. N2 p 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
* F2 S& T' L K( E HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。$ H- O$ x+ f# ]9 r* w; B; J
方式二:. d5 F! q2 Z8 n
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:/ ?+ I* h Y8 R! z7 d$ \
SetTitleMatchMode RegEx, c Q2 S2 `. n: X: z6 |
return5 A. l$ k1 t* W3 I( w4 L
; Stuff to do when Windows Explorer is open
. x4 V5 I# x& @7 C \4 V7 e ;. ~& \: g4 [# x4 H. \6 o
#IfWinActive ahk_class ExploreWClass|CabinetWClass
! a; I, s; l7 z, |6 ~ ; open ‘cmd’ in the current directory
# B9 d# J$ w+ _' p' l0 v ;
% ]. }$ Q0 V5 `; m" W #c::/ E5 S$ ^; d% H" G# @, L9 o
OpenCmdInCurrent()
/ e# F j2 c8 s return6 k1 e, u) k8 z( m1 C) y, ?! r
#IfWinActive5 f+ x7 Q% |5 ?. I$ D
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.0 J$ C8 Q: G! @% N/ C2 d3 B- x7 O# R
; Note: expecting to be run when the active window is Explorer.# I1 [% B* {; }/ ^) I
;
6 y+ U2 B. I5 n OpenCmdInCurrent()0 K }( F) G2 L4 h1 m o
{
+ q$ g- x. Z4 `( D! D# n ; This is required to get the full path of the file from the address bar w p1 p- |4 M0 ?; T- }
WinGetText, full_path, A% k+ e l2 L& _. l! @/ @8 n
; Split on newline (`n)
# |/ p N; D( \6 S6 F StringSplit, word_array, full_path, `n% y' H1 W7 n1 [( ?, i5 V2 d6 U# b
; Take the first element from the array! N' ]% Y& e( r. u* J/ V
full_path = %word_array1%) V- P9 E1 s# d. Q
; strip to bare address$ |: y0 C" g! E" c" w! c. f; y
full_path := RegExReplace(full_path, “地址: “, “”)1 r8 |; [ \: J# |. b" t" b# r
; Just in case – remove all carriage returns (`r)
0 ]0 ]: k- D% x' g7 h* Z: J! s StringReplace, full_path, full_path, `r, , all
& K6 L' r- p. R' f6 _# v9 h IfInString full_path, \9 e9 m5 o- x1 C2 E$ o
{ a) t! z$ I' b) k/ C# D: n+ m
Run, cmd /K cd /D “%full_path%”8 d8 T: c9 K) V, g
}$ _6 k3 O9 L! c4 E1 s7 p
else
! w- `! C/ l p, l0 w0 | {
) V6 o8 L! @6 g/ ?$ T- T9 | Run, cmd /K cd /D “C:\ ” B/ ?1 B2 \" Y
}" _( ]! \& @) V2 I; J8 B
}
7 {0 Q; {- H( v, A 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
: K* Y/ q5 }0 a& v4 y# Q9 B 这段小代码肯能有两个你需要修改的地方# Z! h. \2 W6 t! Z% I( I: O* D* M
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
. X% C& ?3 s T" s' V1 I0 | 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
* v! n/ l- M1 F+ f( W% _ |