此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
; V A; _+ y: E* s5 x4 b6 _ 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
; o! Z) n# o& p/ p) I 方式一:
: Y" \! V. H3 ^1 [3 v1 h1 {& J 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
- F5 h& E/ Y }8 K# y8 f3 W 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和1 X! L8 A+ N* |* f1 B! `6 O8 |
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。2 E' B6 O5 u0 c0 l
方式二:
% K3 a& F6 j7 S3 _3 r5 h$ ~ 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 D) K+ M8 a* X& y3 O" H
SetTitleMatchMode RegEx
+ t, C+ q) E4 _2 k0 [8 T return( j3 P$ a# ?6 r
; Stuff to do when Windows Explorer is open
. p/ `( a' G1 z* h7 O# y9 D ;3 h4 N0 {/ T: }& f0 l* F3 ~
#IfWinActive ahk_class ExploreWClass|CabinetWClass
! l) [; E! R/ y2 Z# ~, h; X; k" {" O, e ; open ‘cmd’ in the current directory4 Q) Z! i" P7 p2 u9 J
;
! m, U8 k! I: U* f3 N #c::1 V; V* W) c0 b2 g' ]
OpenCmdInCurrent()( M6 J3 m7 a& j! C
return
* s* g4 T; e( j- }: k #IfWinActive
& M( }7 r7 N9 r6 E% R( a3 t' a: } ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
2 R; K0 g8 t8 j# ^4 Q ; Note: expecting to be run when the active window is Explorer.
% W% m( p4 L) z# R) J/ g ; W# L5 q9 R6 }% J
OpenCmdInCurrent()( D9 d( n; u- T5 f5 ~3 H
{
( I. y4 f& J% E ; This is required to get the full path of the file from the address bar! z# C' Z, a+ x, @0 h1 R$ e
WinGetText, full_path, A
4 N3 u0 X" h. y; O. o7 y+ f ; Split on newline (`n)" I7 B; ^0 z4 G2 H$ H
StringSplit, word_array, full_path, `n
5 f0 Y4 w# p& R5 v5 o" g+ z ; Take the first element from the array
# B( L$ J9 B$ i. D4 S0 s8 O full_path = %word_array1%
, W" ~# |& \4 X; J O5 g9 { ; strip to bare address
- }, v, L: x7 y$ @0 ]. U* p, m full_path := RegExReplace(full_path, “地址: “, “”)
% D( v3 h/ X7 K" H: D, T0 ? ; Just in case – remove all carriage returns (`r)
9 S) x& Q" K) c/ q StringReplace, full_path, full_path, `r, , all+ s# H7 ?6 V% U# d' f: M0 v5 y& S- @( P
IfInString full_path, \! T7 B7 C0 S+ `9 W
{3 C0 h% f5 E- z/ d: f5 k" y
Run, cmd /K cd /D “%full_path%”: e8 D+ d) z" D- J
}
0 p. t4 x# D+ I2 O; v2 w. y else" h- G% {* l% v& L( W
{
7 r3 j; R) _. M! w8 d; q h4 y: K& z Run, cmd /K cd /D “C:\ ”
0 P- l8 }; _; x/ \ }- v+ _9 w7 I9 ~$ q- p
}
" \! U4 ?* W1 p. a* Y) } 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
, O# N: d2 i( s4 T& d# Y$ j* ~ 这段小代码肯能有两个你需要修改的地方9 `7 r' }# h4 `) R4 q, {4 A
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键$ f$ }" `+ l$ M d' a; Z
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “9 e% Q" Y8 G9 t3 n; j# O2 x
|