此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
9 X$ p( D# F8 \: S" R) e3 t 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
4 C) W' e* y' [0 p 方式一:
; X3 q; S1 w0 ^ | 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,# L" ~8 H0 b; f1 [
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
0 S& M# R( d) L HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。7 S) E# T, j& B
方式二:
9 T3 n/ G( ], y) A, x6 t 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:4 |) Y7 A, ~# B) p+ J2 Q
SetTitleMatchMode RegEx
0 W/ P4 C" @7 L1 ` W( ] return
v+ W1 V# ^$ I( L: I ; Stuff to do when Windows Explorer is open
/ @3 Y4 V% y* |& {" U/ y; ]) { ;
% J' o0 f$ S( H4 r/ J1 F #IfWinActive ahk_class ExploreWClass|CabinetWClass
8 Q' k* J% ^; S" y W# m9 \0 x ; open ‘cmd’ in the current directory
3 `% R* x$ U. t9 b) Z ;
: \) R7 X! T% `+ d( j #c::
3 I& O2 y4 ?/ {/ r5 i* ~ OpenCmdInCurrent(): ^8 j- Q; U) Y0 S9 @
return* s& P% s4 V6 }* h5 E6 A+ p
#IfWinActive0 z( B3 H" j/ C: }' x
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.# H. O5 F M5 u9 E& m0 p, i3 |
; Note: expecting to be run when the active window is Explorer.
8 Y' g- X& f# W; j ;
0 \7 L D) ~% R; @6 V OpenCmdInCurrent()
* L7 b1 Y% r* P- v8 Z0 E% p {
, T. w D, s, o/ [ ; This is required to get the full path of the file from the address bar
- S- g& ~" ?5 ]; q WinGetText, full_path, A& n, F9 \3 I1 I4 G
; Split on newline (`n)+ D c4 H) d, ^) u4 Q! v, R4 o
StringSplit, word_array, full_path, `n- v" y# x9 e, P6 z' ~7 J* i( Q
; Take the first element from the array
, e9 e( D8 \% A+ n0 L4 i# }1 ?6 B full_path = %word_array1%
) T" ~% v/ m: y3 \* } ; strip to bare address
+ O) l+ w' {3 z3 l; B* P0 Q8 d/ K full_path := RegExReplace(full_path, “地址: “, “”)
% R [6 ?- @' K+ m/ V) } ; Just in case – remove all carriage returns (`r)
3 ?: O- n5 X5 l& x) ^ StringReplace, full_path, full_path, `r, , all
5 V& B9 ~+ w m8 C) ~; Z9 z6 q" j IfInString full_path, \5 K( e5 M0 ?, c' k' G% ^
{
4 ]. d, b4 ^) X$ _ Run, cmd /K cd /D “%full_path%”
# ~& j% G/ V( L( g8 Q }
/ z* D; O9 _8 B4 ~+ v+ Y4 U else
. @& w p$ }( g6 C( R" b2 [ {3 Q6 E7 V# ~' X& n
Run, cmd /K cd /D “C:\ ”; n1 E* S' `) c1 S
}) P* D- l# d0 P/ T
}
+ e" ~ \2 }4 } 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
5 D% ?7 @+ u8 q- o7 L. F! u 这段小代码肯能有两个你需要修改的地方
! l% L4 |# k. a0 r. Y& ~ i8 E/ Q2 p 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
9 d5 H( M; u0 }! e$ r 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “/ b# z4 V$ _' q& M, f
|