此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
2 k: r% T) _0 p' G) Y$ w 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
% E4 S6 f& w$ k 方式一:- v8 ~" K* V* h3 e9 ?6 M
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' L' C+ p, P* A: \8 T$ e
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和" e4 `9 `1 K# L% g
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。( W0 v. C% R& V# G+ _) o
方式二:
" a0 Y! K! H' w 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 n- ^- r6 v0 S) ~3 ?; c2 s
SetTitleMatchMode RegEx
" H: I j P0 ^8 s return
% m. R/ A4 ^) o6 N6 U ; Stuff to do when Windows Explorer is open
! ~: |+ k1 L8 N2 B1 G# H9 u ;& M+ ?" Y# p5 m
#IfWinActive ahk_class ExploreWClass|CabinetWClass+ E9 q/ [7 m8 Y7 }0 ^
; open ‘cmd’ in the current directory8 H$ A( l8 u+ N! l& z
; C; Q1 G' u4 ]( @7 s! W' i
#c::2 g+ E; b' s0 P6 ~
OpenCmdInCurrent()0 W9 ?( J3 G7 \: ?! ^9 x2 X, M
return
# C; ^/ a' j! K #IfWinActive
5 N4 c, X" s. z9 Y: }6 s+ @2 Q ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
% R- N' ` c1 L5 n6 N' y ; Note: expecting to be run when the active window is Explorer.
* V/ D8 f( |" C8 o7 \- j ;
1 i1 n) F; o' z8 }9 M, @ OpenCmdInCurrent()% n, E7 K% d' W1 F: b
{
% |8 G5 r1 R$ Z Q, m2 ?8 { ; This is required to get the full path of the file from the address bar6 p- u3 r3 N2 \- c) m
WinGetText, full_path, A
2 H1 V0 B1 W( U$ C( R ; Split on newline (`n)1 A9 Z# s( u9 J* c
StringSplit, word_array, full_path, `n4 t2 m& X5 t0 E1 S' Q
; Take the first element from the array% x) Y& Q' l1 Q: u# P: R
full_path = %word_array1%
! p7 j# h. I$ {* N9 A6 k2 n. M ; strip to bare address4 V' z: l# ]2 S8 q" ^9 D) f/ H
full_path := RegExReplace(full_path, “地址: “, “”). @8 i( n6 h/ J3 O# T, U2 M& ~
; Just in case – remove all carriage returns (`r)
9 Z7 D3 k' v0 Z1 f! z StringReplace, full_path, full_path, `r, , all
+ a& h$ t. S6 ]. L& ]0 t IfInString full_path, \
3 U! }7 s# l: K6 r' [ {
1 Y1 `, l, X7 C Run, cmd /K cd /D “%full_path%”! I( O5 x9 S, M& V
}& x4 M4 N" v. H; p
else1 v- p# C1 a3 i& A* q& S& V1 G- X2 b
{3 m" W3 w/ D& [) W0 @- @
Run, cmd /K cd /D “C:\ ”) H5 X5 @# M) X. w( G! D$ A7 i
}
; L) Z/ u" f8 { }8 F+ l& W- y/ N
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
I u: s. b0 T9 {) }4 v4 X 这段小代码肯能有两个你需要修改的地方
% _3 s" J" v3 m* q) W 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键) e8 P# q* x8 S4 r {
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
( X) E' e8 y& F$ q& X' H2 e4 ? |