此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。0 f. I0 |2 j# D& |6 a( v1 Q
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
2 t$ d4 w: V/ Y( Q0 t 方式一:
# o* ]0 Z) x, |, i B9 i 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
/ L1 j" B$ n2 v 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
0 e7 W* t9 k1 d: B8 c, ?$ E HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。0 s0 M) z+ ~6 f. _3 n. S% s( M
方式二:
2 }/ M4 e+ Z# M9 a* R* H$ H 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
5 U1 x' Y) P6 z3 {3 z3 q% J( s# O SetTitleMatchMode RegEx
8 Q- I8 I) _! |$ z% e8 c0 K return
( R) q3 g( `" u: V! H$ D+ H ; Stuff to do when Windows Explorer is open
5 R& Q) k" {# f h8 w: p! S1 k ;3 H0 ?' ]; U+ K; u
#IfWinActive ahk_class ExploreWClass|CabinetWClass
# f4 J6 n1 v, j$ X4 T; R' l2 E ; open ‘cmd’ in the current directory
- A4 \3 W/ B* M4 R) H ;
4 |- m( v8 i1 k8 B6 k' k #c::
, z( y" X8 V! s3 E OpenCmdInCurrent()
c- c) D8 P! n' K6 B3 h- b4 { return
2 d' f& b- t5 @. x2 Q #IfWinActive1 b$ S9 W2 @0 V( y- i3 A% o. p7 o
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
9 W( A5 ^7 ~) j. s ; Note: expecting to be run when the active window is Explorer.
6 o5 l* n2 \% ^: t+ [7 z ;) `8 |5 V' n" s$ W! L
OpenCmdInCurrent()/ S7 X( a! c- I9 @
{
, F! G( p) a( p5 T/ @ ; This is required to get the full path of the file from the address bar
+ d- m, n7 q; P2 r' x% a WinGetText, full_path, A ~: X- b* Y5 O! S& x
; Split on newline (`n)
, `* `) m& v6 f: e* q, z# v StringSplit, word_array, full_path, `n
0 f, j9 z) t3 I/ S- ], L4 p ; Take the first element from the array z& U/ A* a0 k' O
full_path = %word_array1%
$ g) F+ b) Z! L2 [- p ; strip to bare address# j7 g. c( ]5 D5 s0 z' r: ^; C
full_path := RegExReplace(full_path, “地址: “, “”)
% m' B( [. o, K ; Just in case – remove all carriage returns (`r)1 \0 u, n5 ]- B, m9 `4 j
StringReplace, full_path, full_path, `r, , all
; O' d- O. J( d" B! ?" K# G& m! [" d IfInString full_path, \
. Y6 _+ Q1 e) D* R4 H {
% Z; Q/ m3 f% _ Run, cmd /K cd /D “%full_path%”, A+ R6 F7 k3 [6 N; ^# Z
}9 l, G. ^6 @5 \: ?& c
else
+ ]+ D7 A+ B5 e# ?8 \, @5 f3 S {/ m4 f, c5 \3 J3 j/ a8 ^
Run, cmd /K cd /D “C:\ ”4 t. {& G4 I+ l: W
}$ q/ ?( D( ~1 T7 v/ T% L
}
! \, l+ L" k7 w$ }8 E$ y 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。9 Y$ Z' ^) d: a" G {- Q
这段小代码肯能有两个你需要修改的地方
8 o0 Q. g) Q2 f0 C1 m4 l 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键) s7 n4 @- G8 f1 A" C: Z
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
; K4 x3 ~2 [) y3 Z |