此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
) F T$ Z. b6 y1 P, j5 t- \3 V 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
, v$ [0 M7 V2 H* [( n+ V- F' `8 N+ q 方式一:
, z4 I7 {( l! @. @; W" T% L: D0 H 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
7 |; m/ l5 d& F* {2 ~1 W! s) n% r 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
( z3 R V+ T9 X HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。# X2 w# D- s+ F* a$ V
方式二:% @; Y" ^: u" P/ t* z8 R' T
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
5 n0 T- A, ?! B, e2 S SetTitleMatchMode RegEx
* T8 [0 m) F7 Y5 f ]6 I return
; C1 l: J. m8 {, Q ; Stuff to do when Windows Explorer is open) s9 O* r6 t, r+ D
;
3 A4 C3 ]. y+ t( q' ]4 i: \* d #IfWinActive ahk_class ExploreWClass|CabinetWClass# E: {! v0 r" K8 E6 F
; open ‘cmd’ in the current directory
! n; d! E* U3 O+ X* K: u0 J ;
9 i; f/ |1 k" ]; z! E G+ z #c::
7 \( P$ j8 O* } OpenCmdInCurrent()5 X0 d8 k: X- m3 F0 H( `( Y
return% g9 Z% g! Y$ W& @6 j2 w! \
#IfWinActive
( _2 R+ b6 m: q. B+ R& a9 \ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.- v- C/ F, v$ B/ D
; Note: expecting to be run when the active window is Explorer., _! I6 K; A& ]7 h+ t9 X8 t o
;% B/ R3 |/ I% F$ F" U
OpenCmdInCurrent()
9 h) C! p! t% I2 p- F- L$ U {
- M. P% h+ D, U$ Q# D& X ; This is required to get the full path of the file from the address bar
# B& }; _7 i( m( Z: u WinGetText, full_path, A& N; C& G; K: Z
; Split on newline (`n)& R$ b( q# P# T% @* I8 D
StringSplit, word_array, full_path, `n
0 o, c. K7 E' M5 a$ k ; Take the first element from the array
3 o3 _( t/ N; R9 y! P full_path = %word_array1%' X* ^6 T6 @" w+ m3 V
; strip to bare address
2 k1 u. D. q* ^: t full_path := RegExReplace(full_path, “地址: “, “”)
- W/ s1 b) t$ c! h4 i0 E ; Just in case – remove all carriage returns (`r)* a* O: v/ Y1 o4 X+ K; B
StringReplace, full_path, full_path, `r, , all- Z* }8 g+ b+ ^8 ]7 h% ^
IfInString full_path, \
6 ` d+ G% U3 \6 K0 y7 V {; F5 w8 D$ L/ u. ?2 i% G
Run, cmd /K cd /D “%full_path%”
* T9 S/ @2 o) L! w }4 [3 I! f4 H; d) w2 h
else2 n: u, Z) `3 ]6 Z8 z" s" g& K
{% t' N, ^, i. l/ g
Run, cmd /K cd /D “C:\ ”- l/ t7 ?1 Z5 `
}: X8 u6 E% G( W) l
}& Q U% [/ S; i! X3 ?9 @
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
( U3 Q1 j6 H2 ~, E3 z8 k 这段小代码肯能有两个你需要修改的地方
; L' ~& \* O- X2 [- e 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
5 I5 ?' L& T1 v. h9 h 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “" }& h( P3 B6 `9 D4 r
|