此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
' K( n" a1 D1 H) @ 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
. A v1 \7 t3 N0 s! E6 M 方式一:
% ]) o" }% D- }5 |4 e6 o 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表, ]$ v5 i! M: c8 R/ v% L( r9 M
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
- U# L' m& S/ H1 ?8 C) y0 L* ^ HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
6 u8 |( O, h% | X# _# x, Z* c+ ]" D 方式二:
+ g1 L) p& {9 a/ B% ~! S4 i 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
6 @- v" s* J1 q, G SetTitleMatchMode RegEx
+ Y) D S6 n `6 c1 ? return
5 e: B0 f8 X. c+ d0 T) D ; Stuff to do when Windows Explorer is open9 B5 V% c3 d+ T6 L( m$ ?3 R$ H$ D) B
;) d" \1 t7 e+ U/ k: R
#IfWinActive ahk_class ExploreWClass|CabinetWClass0 i/ w7 i( h2 D* v: ~
; open ‘cmd’ in the current directory
9 x# G( b% }0 q r ;
7 t' t; E' {+ f$ V. d( c #c::6 P( V6 f; Y$ P' \+ D ?) c
OpenCmdInCurrent()
# X/ N. ]/ T# Y return! V3 _ [' y1 P7 I2 ?0 R
#IfWinActive
$ { g' l' ] m% Q ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
9 Q/ u5 L% }* E9 } ; Note: expecting to be run when the active window is Explorer.7 d' w5 V7 n8 a- k. X: I+ w
;
3 P: }# |/ Q9 {- U9 g4 X& p OpenCmdInCurrent()
1 g0 S2 Y. j Z* q {+ p9 L3 _4 h Z9 V/ |& R
; This is required to get the full path of the file from the address bar3 g v5 Y6 W+ A; v0 [+ t
WinGetText, full_path, A2 ]3 I4 W0 X! m9 H
; Split on newline (`n)) y, s+ b( L( [/ u3 t2 Q2 R. h/ `# v
StringSplit, word_array, full_path, `n, d8 ]# S: Y# E. E: l, s( T4 V
; Take the first element from the array; q: D# [4 i3 x
full_path = %word_array1%
7 q+ i6 |, C$ k! ]: Z+ y ; strip to bare address U' f1 a/ N4 {* o) ]% z
full_path := RegExReplace(full_path, “地址: “, “”)* }3 r6 _$ K1 v9 v
; Just in case – remove all carriage returns (`r)
. j% W, s- g) A3 [$ \ StringReplace, full_path, full_path, `r, , all
$ M7 }6 P7 \% x, A: I/ U0 G3 V IfInString full_path, \& R% {- W6 v/ Y9 C# n: K; _& S& v
{
9 v2 s! N& o, }: s Run, cmd /K cd /D “%full_path%”
0 d/ W, x- N l" ]5 U }
8 m5 m# f& S3 y" J* r# ]7 ]! c8 f$ z else# b: O; F7 S3 I7 G l9 ^: U9 T% i
{
* a" a" U. @! D$ J, ]" `# Z0 c/ B Run, cmd /K cd /D “C:\ ”
, f! p9 a) f! N' \ }* h, c4 c4 F7 k) g- }
}
' t9 m9 c( p- N 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
8 |& \. r# V8 X) w; N/ x, _ 这段小代码肯能有两个你需要修改的地方% H0 D8 t4 {* ], U. ~' U2 ^
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键" H* G4 k9 k4 f3 L
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
. V* w7 S* F5 o |