此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。. S1 T' a0 C( h) `
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。- a8 R/ R6 U; y; Y
方式一:
/ R6 e# l; b0 M4 n& D- c1 e 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
8 h! l' t5 O$ h, [ b/ f* {' } 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
; g4 m4 e9 C/ a# [) B' W8 q( I# l- F HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。: B1 i9 ?4 z& Q
方式二:! T" }$ r/ V( q* d
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
* W* L& X! l, B4 E( V SetTitleMatchMode RegEx! p) p" M7 b' d0 v/ Q
return( V, d, Q" W! t/ j* h
; Stuff to do when Windows Explorer is open
/ d O6 ^) p- [' { G5 O1 d& u/ f ;
H( \& p" }2 F4 Y e9 R #IfWinActive ahk_class ExploreWClass|CabinetWClass8 t. ^+ w0 K$ r+ ~
; open ‘cmd’ in the current directory$ C2 l' ]8 p4 b( a! e2 R: w
;
+ a0 P' {4 |7 l #c::
+ l+ y; S9 g( R" V a2 p OpenCmdInCurrent()
) S) Q1 r( O+ f return
. U3 T, w% u1 ~$ W, d1 v( U #IfWinActive
# q9 g; J: p8 |1 p3 ^ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
$ J0 H! Y) S9 C- q8 |7 y9 x% Q/ c F ; Note: expecting to be run when the active window is Explorer.' C% [- Y2 {. e- _
;' ^: V* H" F5 \9 S
OpenCmdInCurrent(), {: g2 N: k: l' j
{
% J* M4 _3 x6 F# c( L5 }$ D$ Z ; This is required to get the full path of the file from the address bar
* M W) W9 o7 {0 s WinGetText, full_path, A
+ z* W2 H8 `! a# Q; n ; Split on newline (`n)
* s' T" }; D {7 q% ]) N% ]# z8 X StringSplit, word_array, full_path, `n
7 V2 f {* V6 n! ]! k, d2 r ; Take the first element from the array# _7 @2 E3 ]5 A( X k1 k
full_path = %word_array1%0 S1 j5 C" y7 X9 L! `) d _* g: P
; strip to bare address
0 j! E1 M: J7 @& I& M/ a full_path := RegExReplace(full_path, “地址: “, “”)
+ N% G4 r/ A* e' d. y% H" }6 y' b/ m# E ; Just in case – remove all carriage returns (`r)% B$ ? q) w! g5 j
StringReplace, full_path, full_path, `r, , all
# R9 {% o3 q R. X m. Q IfInString full_path, \5 R' ?" y# D* \# O. A
{2 F5 l. S! E8 l6 i
Run, cmd /K cd /D “%full_path%”: D, H; g' v( \! a9 r3 A9 ^
}! { Q* V3 B9 }' L
else6 }6 b# j. F W3 K( a0 }
{
. A1 Z8 U7 A f+ Z7 u, q# @2 N; k Run, cmd /K cd /D “C:\ ”. J$ D: A8 j9 q& p6 U" K2 K' q$ M
}
: P4 B* T i0 I) C/ b( `6 a; D1 H }
. i- D9 q8 }: D2 @6 q' b$ X$ C. Q 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。 c$ i- e# J' {- W, s+ R
这段小代码肯能有两个你需要修改的地方
+ v5 e {3 X1 [; f2 M 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
; \4 H7 |( O# i/ Z) c4 n& F7 c 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
' S( W5 @: [- K6 {1 F |