此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。5 D# v9 }9 p' E( K( o" h! |
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。0 v& s6 I1 X3 F: q* o5 b
方式一:
; p8 b, H( H8 d 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,3 B5 S3 f# E8 z0 a% I" R: R
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
~, C( X3 ]! U. `; y E HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
( J" ?% e" p3 T! Q" E 方式二:6 j0 T) V1 _) Y9 r! _$ e7 p& j
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
; M; y6 ]0 H; E7 j. N W9 Y SetTitleMatchMode RegEx
2 e- Z4 S a `4 a4 u return! k# d- i( w2 k" X, t2 m& a) d6 S
; Stuff to do when Windows Explorer is open/ X# O# Q! k/ ?, O' P3 Y
;
3 {) J* i; U0 H" V2 B8 r #IfWinActive ahk_class ExploreWClass|CabinetWClass7 L7 J% t: x, i0 b0 v/ e
; open ‘cmd’ in the current directory& j9 T5 D) X6 n
;
" G1 a9 w4 C% c$ ` #c::
8 G }' o8 `) g9 E% x0 i9 |7 u# A OpenCmdInCurrent()
! I% _/ [' e" E2 u4 K J9 L return
3 ~* ?( _' [7 C2 w# I #IfWinActive
- o. H( L( [) ^! ?- S' P ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
! {! Q6 R8 i6 k$ f, S0 j& ] [' w ; Note: expecting to be run when the active window is Explorer.
, g: V5 }1 z, w- y2 L ;; V- z% ?1 \5 ]$ s+ {" p( v) {" F
OpenCmdInCurrent()9 f1 V/ V0 p& Y9 K8 H" E$ G
{
( _2 B" E7 L* N2 z2 a ; This is required to get the full path of the file from the address bar* o8 V H( E; h
WinGetText, full_path, A& t& |8 h$ y3 X6 s1 d
; Split on newline (`n)6 y" f4 H8 s+ D, ^
StringSplit, word_array, full_path, `n
) a- t: b( |. J6 E4 i4 ^# x, T ; Take the first element from the array [- x4 t1 N; i8 n4 y
full_path = %word_array1%
& H; o0 {# s. g( ]) ^ ; strip to bare address
( u( w" ^1 E+ Y& T& Q* a; S full_path := RegExReplace(full_path, “地址: “, “”)
( t, W; m! ~! l: W# F/ r$ C ; Just in case – remove all carriage returns (`r)/ z3 i9 n* Z2 X9 q
StringReplace, full_path, full_path, `r, , all
# R# Y9 f6 X" X, g5 ~) @. U; Z IfInString full_path, \% l# p* E* C6 E
{
0 R& W/ x/ S5 O7 Z Run, cmd /K cd /D “%full_path%”
3 w! i8 S4 c s$ B) F* O3 v }, _2 D! v6 {7 ~' u$ ^8 X$ s
else% u0 S; W# s( l5 z& a
{
0 L2 M: @- z& R% f8 Z Run, cmd /K cd /D “C:\ ”, I- S; J, t+ B
}" A/ ^" k2 s a# {; P
}
2 P5 T3 P3 }4 h 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。' }0 x; l: p R4 w7 c5 c: A& U/ g
这段小代码肯能有两个你需要修改的地方) D) r8 B- T# J: z: M" ?8 B" t8 U
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
% @ \6 H U2 M8 x 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
. e' U0 s6 h/ G$ {( b |