此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。# B# g _( S: ?0 [! K9 X n6 W" P
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
4 ?/ l, Y$ q% N9 u 方式一:
" b) I6 x. W% }6 b, W8 |$ J 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,7 C! h$ c! Z- G$ E( j2 K
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
+ O* Z' O% I/ U Y' @2 H# d HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
; `) _& P. E6 {7 X- f 方式二:
6 z' G& m1 S$ c8 A 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:) u( o5 c) x1 v" D' @3 x$ ^
SetTitleMatchMode RegEx
. u7 T) e& z: _ return
/ c: m& C: z5 |. V. F) {3 d ; Stuff to do when Windows Explorer is open
- {* y2 s5 T7 l. m' d0 H- C6 ^ ;: y( k$ m3 q p1 M
#IfWinActive ahk_class ExploreWClass|CabinetWClass! o2 \; l0 P! h! w5 y
; open ‘cmd’ in the current directory
% E1 y/ n# `, E! A4 X ;, j6 m7 ]% p1 _/ w9 v9 Q
#c::
$ _: N7 H% D; F4 N0 a& J' w OpenCmdInCurrent()
) a1 y5 \ X% X( S) I return
" C- L1 H: l4 M" i1 T- J #IfWinActive3 X6 _' a9 K% l9 S
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.! P0 C ]2 `' x6 u6 O1 T. I7 \
; Note: expecting to be run when the active window is Explorer.
5 [' | t3 h; R/ Q; a' |+ K% F ;9 ~( P+ I9 q6 j; v7 Z. u' Z0 X
OpenCmdInCurrent()* l6 `8 w: O# D: k# K
{
0 M* v& U: C. `* S; L$ j, D S ; This is required to get the full path of the file from the address bar
# O' L: O1 U) R- u WinGetText, full_path, A; B1 P! w( q- G
; Split on newline (`n)4 Z2 Q2 M, e" p6 w6 h) ?. ]
StringSplit, word_array, full_path, `n
+ J" B* x: e0 c0 ?0 v ; Take the first element from the array: W: r, s9 n# Y4 W2 ]( p
full_path = %word_array1%
! {1 y+ _5 Z6 S* f- r% P) k" m+ n) y+ c ; strip to bare address4 q6 \% C( T6 W* s; L8 s0 g
full_path := RegExReplace(full_path, “地址: “, “”)6 r# O' c) n8 C4 _9 `7 L
; Just in case – remove all carriage returns (`r)
- ?0 q: l8 }: X& h: B' r, ~ StringReplace, full_path, full_path, `r, , all) J/ Q* t& W8 A5 |
IfInString full_path, \& l: q+ }) w. L
{
, z0 c. Z$ _- h! `1 j4 Y Run, cmd /K cd /D “%full_path%”
! y4 H. ^" V; R2 v7 g1 w }
5 y& P' T8 S* L; f8 p else- l. a8 f- Q1 Y Y6 C* |
{( K3 ~# q3 E1 X3 U3 u/ S
Run, cmd /K cd /D “C:\ ”
# F! b3 W6 J- r* F6 i }5 _" J Z: D1 W2 u, z
}# d3 L9 o+ M+ H& K+ B# t$ G7 u
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。: [1 t5 C7 G8 P! ?; r
这段小代码肯能有两个你需要修改的地方
) e% \) |1 U7 S 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
2 b: Y T9 @: n/ G' n5 C 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
" z/ V' R2 i, } |