此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
. T+ S4 S5 i+ E3 V) r7 K) c 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 H/ j% b9 i; C; ~: Q/ { 方式一:9 s. q6 n: b' }8 ~
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,7 [2 v4 {- `0 G- G0 g9 M& W) m% j
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和+ }+ G0 y8 z1 m* Y/ m* l' v, e
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
: M) W$ Q7 ^, K/ v 方式二:$ k( |) x- r' J
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
$ f D8 H, \4 D0 C; W SetTitleMatchMode RegEx
+ t- V2 J/ D6 J" I" Z5 r0 P( { return8 M/ A9 Q# o* d" B1 g4 q8 ~
; Stuff to do when Windows Explorer is open& ~4 o/ t8 z) c2 f0 A
;
7 u( Z, t; w; K1 {; K, n0 v* ^% ~" b #IfWinActive ahk_class ExploreWClass|CabinetWClass% w! L0 O% o" U, W) [- \" m/ }5 g$ @
; open ‘cmd’ in the current directory
: t# R1 M' [% p d. F2 j: R; N& i. Z ;
: F. [9 n% C. u& ? #c::
# ]5 Z, @' _( h OpenCmdInCurrent()3 H+ M+ o! h% w
return% b# p$ M( [9 S
#IfWinActive2 z$ A6 P0 y( K4 n6 X5 s i" ^
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.' X) y: c! i* z( n+ r! [/ y k( p
; Note: expecting to be run when the active window is Explorer.
" o: Q; ~; c. |1 x: l1 O7 Y/ H ;
9 w2 K( U9 z6 ^; |" g; h4 x% f OpenCmdInCurrent()
% F8 H. I' E* o/ c9 _ {/ r. h5 y" I; S8 |' ], X
; This is required to get the full path of the file from the address bar6 z! A2 h1 Y2 S, O; n
WinGetText, full_path, A+ f' i2 ?5 [% d% J
; Split on newline (`n)6 U7 y4 ^9 B1 e. a. t- n
StringSplit, word_array, full_path, `n
' U3 D4 M0 J! L+ w3 M! s ; Take the first element from the array/ K# ~3 e0 S& ?1 ?7 u, g( _$ ^& R
full_path = %word_array1%- f. z9 i; w7 ^$ M* p, J
; strip to bare address7 ?! s# X& e# Y# R6 T9 M
full_path := RegExReplace(full_path, “地址: “, “”)
0 ?5 Q1 m/ m. z9 q ; Just in case – remove all carriage returns (`r)* _# y( N' n% W$ M
StringReplace, full_path, full_path, `r, , all
I& `4 D" A6 c1 \8 Y. `, ^- H IfInString full_path, \
5 V8 o# i8 I! _8 I' I- ~' ~4 F {# b5 R6 r3 T5 }. A, f
Run, cmd /K cd /D “%full_path%”
. t( `& {) b! w( d$ ? }
' R/ u- _, u O( x6 y. K else
+ V. B$ l* t. N7 u( A! O {. Q: T; {9 D; T4 H! F
Run, cmd /K cd /D “C:\ ”7 I6 u) e6 g4 l' l1 z, f9 J
}
/ N1 f) C0 B! v$ y/ W }" `) z7 C3 c3 p+ u# k) J. {
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。* b- L1 i1 J3 W e
这段小代码肯能有两个你需要修改的地方
_+ A1 @3 O" d+ B/ U3 N 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
& L8 h& r, S7 |$ Z! v 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
2 d0 ]4 B# m& s3 R' c |