此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
% a6 u: w8 `' A4 @- S7 J% R 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
* [9 b. w1 ~3 t" n5 H 方式一:4 k6 O) \* T9 U& y9 G- m* H
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,* h9 n* J3 f9 q; Q
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
/ P7 t6 W, I: Q3 h2 D HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
8 H9 l* C4 t4 M% |) I 方式二:& x) c& V, v" `9 b
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:& c5 Y' z1 `! S" @. P$ m
SetTitleMatchMode RegEx8 x; u: {5 q6 c
return1 n# \" ?6 w$ i% U! Y5 v! t$ k
; Stuff to do when Windows Explorer is open6 b7 O r% o- `) r
;
0 M6 O3 G3 X. Z' @' ~+ f0 g, G #IfWinActive ahk_class ExploreWClass|CabinetWClass
6 d1 ]+ @! J: z$ s- e ; open ‘cmd’ in the current directory m. e% l* C4 K$ m
;
- g; O4 v8 R5 |- x #c::3 a8 r. E4 M8 s7 @; z! B/ g
OpenCmdInCurrent()6 n! w1 ~. e6 M% Y3 `2 L
return7 R$ l9 s, m: k/ O+ Z o
#IfWinActive/ g5 G6 b e! `
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.: c; m1 I2 }' u8 D5 i- v5 }
; Note: expecting to be run when the active window is Explorer.& K& E# d& }; c9 I; h; f
;
/ U, m9 \# G A F* w OpenCmdInCurrent()
) N/ m+ z' [7 U) e- c9 ?* i {& O- j3 K1 t3 O- n9 l, V. p8 ?$ X2 [: J
; This is required to get the full path of the file from the address bar: B# k2 [: V# @6 t5 f- S; [
WinGetText, full_path, A
( C E: F$ I; a8 G* a8 N/ g ; Split on newline (`n)
9 I6 b0 Y+ }" u! J StringSplit, word_array, full_path, `n, y) f6 e0 m& F. d! r {! F* v, {
; Take the first element from the array
O6 A3 K& ?# l- {) F full_path = %word_array1%
9 J3 Z5 G1 O( J) } ; strip to bare address; O; g Y! K/ ^4 g# D0 A
full_path := RegExReplace(full_path, “地址: “, “”)6 ^, l H4 i# L- D
; Just in case – remove all carriage returns (`r)6 H: v+ h. Q- j1 Z6 l
StringReplace, full_path, full_path, `r, , all
7 o0 X' Q' u8 F- l3 n IfInString full_path, \
4 q1 S9 k/ h5 ~% ?/ I' q ~ {) A$ U3 p# {3 b7 _& s+ D
Run, cmd /K cd /D “%full_path%”8 b+ V5 x- m1 S" e! V
}
; v' V- T+ t3 W$ r, W, |+ C else/ h' B" Z# [6 a% w* w
{ [' j# K2 n- O' C
Run, cmd /K cd /D “C:\ ”3 `2 B% ]+ e* ^' Q9 g6 T
}
) Q$ l1 O6 {( L# T4 I }* W. Z( {" B+ w4 D2 J+ {
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
& P& v) D4 n( s1 R9 Z/ d 这段小代码肯能有两个你需要修改的地方' |' N9 {) @4 m, i
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键: J. c. q7 X# R5 u% ?6 i7 j8 B
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
3 t o, G6 c% {$ ` |