此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
. | W& }% N7 a9 E& N5 j 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 X) `8 _/ y# }" Z" Y$ w- ^' N 方式一:! a8 T9 C7 r; U9 z6 j9 }
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,6 T7 T6 T* p" N# d9 L! ] \
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和9 l/ w! Y9 M6 a0 w+ p
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
) K4 V G) j8 e7 V7 i" ]) K- ?0 H! E 方式二:9 `7 c& a8 K8 G, y" R4 }
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:6 ?2 R3 t( o: x
SetTitleMatchMode RegEx
% B F. N! |* O& n2 a return
; n$ C" M: S6 G& f% V5 \* d* y1 i ; Stuff to do when Windows Explorer is open, |- p8 v- ^0 A- t. k Y. ^' ^
;
2 L$ m" X7 n% n+ p& l; j( N/ h #IfWinActive ahk_class ExploreWClass|CabinetWClass o! k) n$ m6 {8 h4 |
; open ‘cmd’ in the current directory
; S8 x, C2 N0 O2 D! ~ ;
+ i' [ q' I1 @2 O5 e; g4 y #c::
: `, N; E r( a4 y) E OpenCmdInCurrent()( n* Y0 X, T G! j( A1 x
return1 B2 a3 c4 s5 L: X
#IfWinActive. U& A/ x2 B, t r0 k9 W. v3 B$ G
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
, [7 U8 f/ z- l% N! ^ ; Note: expecting to be run when the active window is Explorer.
6 t4 r0 [0 U. ` ;5 z i4 g' {& T/ _2 J f
OpenCmdInCurrent(). t# I V5 p# \
{0 N5 h# H' m1 c3 ^
; This is required to get the full path of the file from the address bar1 }0 B/ H/ ~" R+ E8 _6 Z2 [) l
WinGetText, full_path, A
- d% h' Y+ J0 e1 y+ J0 z ; Split on newline (`n)9 B; i6 r& e1 Y% M( x# x4 m2 M
StringSplit, word_array, full_path, `n
1 [: p' y% W: R9 K' A ; Take the first element from the array/ i/ P% f/ _: i7 p& ]4 x
full_path = %word_array1%
% c B0 b2 F) W( ]* e+ z ; strip to bare address
# _& V9 }/ i) E' }0 ]6 V( | full_path := RegExReplace(full_path, “地址: “, “”)$ I' @4 ~ n$ M% d7 p" J
; Just in case – remove all carriage returns (`r)
! O8 d5 [$ z- O7 E StringReplace, full_path, full_path, `r, , all9 C: E% K( N' I, K( _( B0 c
IfInString full_path, \" b% J& B5 g3 j2 f: l+ @9 s' f
{5 y9 u' u. J- ?9 s. z4 A) O- p
Run, cmd /K cd /D “%full_path%”
( `7 Y7 i; _% k }9 {$ S& k$ g# E
else* e; h" j% W/ q/ B" Q' u
{
( z2 M6 A" g/ e* ~8 u- e; e Run, cmd /K cd /D “C:\ ”! F* j+ d% e4 D [
}
& T0 y8 _6 S' i! q* D, | }$ E, z3 N6 J. F
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。6 A1 |& f2 l( r1 u! `5 ^
这段小代码肯能有两个你需要修改的地方
; Y2 {4 T6 r; J* H0 ^. b6 v 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键/ e% F a6 `- i7 Y# d7 l2 T
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
) n- j4 r* z. p7 G v) S9 o; B |