此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
6 M" N; }0 S% C" F" N- r& N 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。7 i* s0 s W) C! P I1 C) t
方式一:
# v8 \) @4 B/ u: {6 e3 V 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
t9 x* z/ j4 @, R( N0 M 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和" Q2 l4 p. x* d* K
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
, t# G4 o& b0 w5 _: u! M 方式二:/ O) i5 w8 C1 R7 Y
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:. t* X) I; f3 \
SetTitleMatchMode RegEx
% x( y7 z7 b* ~3 ]* G return9 L. ~: J f% ^/ Z
; Stuff to do when Windows Explorer is open
+ T& W0 I* S7 G' | ;
$ z9 P; f+ X' y; C0 o #IfWinActive ahk_class ExploreWClass|CabinetWClass
7 U1 Y! `7 K/ f" Q- S" \ ; open ‘cmd’ in the current directory/ i! v, H% O- ]) V1 _3 S* s
;
( S) z' @1 c; Z* q #c::* \, A- O: Y. O
OpenCmdInCurrent()# ~) G g0 K2 P4 o* X# t0 V+ D, K3 g1 a
return0 D* b" ^5 o* d& `( Z( z
#IfWinActive2 s1 Z8 ^5 r) l) F. e9 @
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
) ?; q: N! u% D* I B2 P ; Note: expecting to be run when the active window is Explorer.
# c- ? h8 B. K0 n. D ;, u6 i( a% B# p" M1 t
OpenCmdInCurrent()
" i% Y( b9 Y, ]0 t- i) [ {
) Y2 h# Y1 d! {2 b4 ` ; This is required to get the full path of the file from the address bar
' T& r# s# M, @. R WinGetText, full_path, A
$ s( y* `' D+ i2 s ; Split on newline (`n)
; U2 \/ @" W$ v StringSplit, word_array, full_path, `n
$ R) }+ I8 @9 h% k; J8 v/ Y9 g ^ ; Take the first element from the array" |6 y. n _; b. C- t$ ~0 z# }& w9 [
full_path = %word_array1%
6 u2 e& i& Q6 M: b9 P ; strip to bare address1 j j& p0 d: q1 O2 O, H# h$ s
full_path := RegExReplace(full_path, “地址: “, “”)1 I# M5 ]; T4 s7 T% b* M; I) h
; Just in case – remove all carriage returns (`r)
3 u, x8 r' b% Z5 s" ?5 M7 w4 [ StringReplace, full_path, full_path, `r, , all+ v$ V% _ p* N8 o% m- a
IfInString full_path, \
6 G: a/ W4 B5 N/ b P" H, ] {
5 l# s) C- v8 A Run, cmd /K cd /D “%full_path%”
, J: g7 n0 H! w \+ K }" ?, _/ p' z& u" I. w2 y
else) D! J( i# F1 V! y0 O9 g
{
: j; }/ B/ ]0 Y' i; c f' ?! Z Run, cmd /K cd /D “C:\ ”! v% P1 j# {$ o' e# R- p9 S
}1 H6 B4 @2 J, A% G( l
}4 U! [2 @# D3 o& B
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。 H; ?1 Y5 v( x1 L, n
这段小代码肯能有两个你需要修改的地方9 u& K" X, w& H/ x2 w, x
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
; E& A) e# ]% ?1 f6 w. Y9 i4 t 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
, ~9 ~ }, \, N" a# p: U6 x* L |