此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。* d/ N9 `0 N( H! r: d& L' |
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
n& ]& b' G/ ?# S! t% ]2 ] 方式一:
- b+ p. o, t2 [9 x1 W' c+ Z& l 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
' d$ i7 g! p, a; z4 ~3 X 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和1 Q' T0 M t! {" F0 v% `
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
1 h/ r! R( G5 n5 W 方式二:8 I$ S1 O2 D( s7 b
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
# }) G: X' ]: F SetTitleMatchMode RegEx
' z3 l8 b! I6 x1 p" U, H return. C8 W9 V3 O0 d
; Stuff to do when Windows Explorer is open1 `# g1 x) l; @5 a+ m
;
! H5 Q. h3 m: e$ d/ d! A. t #IfWinActive ahk_class ExploreWClass|CabinetWClass1 u, V" T8 V; ?4 X' o) \, `& N4 q
; open ‘cmd’ in the current directory
- e: b) j9 H1 \, y& _! b6 y9 s ;5 Q A4 N1 A6 n$ X& k
#c::2 ?9 _ K6 ^& V1 W% D7 N8 r+ l
OpenCmdInCurrent()& z9 b. Z W+ C- d, P' n; j
return) G% \+ L1 l; n r
#IfWinActive
7 ?" B) x* b" K1 I ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
% ^! z) ^ G: C, C5 E" g7 x- _8 A ; Note: expecting to be run when the active window is Explorer.9 q; n4 M9 `) x3 F m
;/ H* g% b; B' o. O4 C4 l8 ?3 T
OpenCmdInCurrent()
- _% B4 i) J3 r. P2 J {$ Y$ W1 x* x) P: m$ o
; This is required to get the full path of the file from the address bar$ x; u8 B- L9 e# j& Q) t, l0 K4 x
WinGetText, full_path, A
2 a! A# X& Z8 j8 Z$ R' m ; Split on newline (`n)+ p7 n4 f' F) Q$ K5 m" n" F: a
StringSplit, word_array, full_path, `n, c" ]# u/ g" }- `* l I
; Take the first element from the array% N: _8 v7 ?( L ^( Z! |. E2 ~
full_path = %word_array1%
8 J# c& ~3 a3 F! Q3 ~0 b% G& | ; strip to bare address6 G5 W) F. }( V0 B! f) K: i U
full_path := RegExReplace(full_path, “地址: “, “”)
8 l- a, I$ ?0 v, ~ ; Just in case – remove all carriage returns (`r)
6 t) f6 [& B# @4 ~, u6 v) X) ~ StringReplace, full_path, full_path, `r, , all
0 ~# y* J; g3 {$ L |( E L: i, g; J IfInString full_path, \0 A2 Q/ q2 N6 \: g1 d
{
! u: x$ F. L3 d6 s$ L n3 r# i Run, cmd /K cd /D “%full_path%”- i, F# J* y4 y" p o* T2 [
}
( m; s" c/ p" h4 z6 o. L else
4 b8 J% _( K3 f {4 A& x- M0 @: \
Run, cmd /K cd /D “C:\ ”1 N# J, k) J U7 V9 K j$ s
}% p2 s5 C$ r% Y* J! o
}- ?# |$ _9 O8 [- Q4 }
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。$ M8 q, D% C, ]! ?
这段小代码肯能有两个你需要修改的地方+ R9 g) t2 @- i' H
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
, `. X1 @: ~6 x 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “( Y; [8 g+ M) s
|