此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
" D; @' j* `% L9 h; h% @ 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
1 l6 I* w, g) _ 方式一: L( f6 q( c* _; d# ~9 F) r* P
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,4 Y3 P7 [. [3 ]9 Z$ R8 Q) |7 J
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
9 X. b; B; N8 K4 R8 }. e HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
& g; `- a( Q: D' l" b# N9 H$ g; i 方式二:
, `/ H3 s) d* X% ~. { 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
3 b- A {$ B; C1 u& S o$ G" f SetTitleMatchMode RegEx/ m" {1 c. _' f. D5 U1 q
return. f6 \% N+ ]" \! }! L% q6 c0 M& I
; Stuff to do when Windows Explorer is open
" u5 z3 X3 ~; `& u: t0 K' c5 W% b2 T ;
6 Q- a! W' n) X6 w& x' w! s #IfWinActive ahk_class ExploreWClass|CabinetWClass% c, ?1 Y, g$ ?! K' }& `
; open ‘cmd’ in the current directory/ N9 G2 i; b& a6 P" m* d' s0 n
;6 @" q5 `8 \9 q2 I |
#c::
. [0 u* ^' j/ M$ A; p8 n OpenCmdInCurrent()
2 {; }# D1 `0 o O& y4 n* | return8 e4 p. y4 f5 o
#IfWinActive, N& A6 l. b/ O' b" \
; Opens the command shell ‘cmd’ in the directory browsed in Explorer. {" g% P$ Q- L; a) q, `
; Note: expecting to be run when the active window is Explorer.- H; Y9 v9 `# O, L) E/ l! D5 h
;+ U5 w N7 l9 B7 S' V+ d5 Z4 _4 P
OpenCmdInCurrent()
9 x( z/ z2 g# l! q4 p0 I' _3 J {6 ^$ {* @# K" Q8 E4 k2 ^# N% C5 j
; This is required to get the full path of the file from the address bar# ~+ T5 [* C2 T
WinGetText, full_path, A' O$ A( i- ^; F* S& q
; Split on newline (`n)
+ D. y( P6 Q9 x0 U3 P StringSplit, word_array, full_path, `n
& d+ J$ h- W+ L- h- d0 R+ }3 C ; Take the first element from the array4 E9 Z' U6 Z" n) K$ j- d5 H
full_path = %word_array1%
3 S7 P5 i z) J! F ; strip to bare address
: {5 i0 ^- H+ k' P full_path := RegExReplace(full_path, “地址: “, “”)
! b- v# C! O% J. s) F: w$ f) ~! M2 p) K ; Just in case – remove all carriage returns (`r)8 W+ n: o3 K+ k8 I; M4 Y: z
StringReplace, full_path, full_path, `r, , all* ]% ?. z3 j: O. C
IfInString full_path, \
( r( f7 s/ x1 Z {0 Z* e ?6 Q# T1 j. z$ D$ V
Run, cmd /K cd /D “%full_path%”% H) r7 T5 {4 t) t# T# N+ b& i6 r) w
}
/ U3 p& x5 `* M# H0 \ E else, Y( |2 u& \1 R$ g, M
{
% z5 j; }3 t. F" R0 ^7 c9 j Run, cmd /K cd /D “C:\ ”
* e1 t' ` @% y+ ^7 o- g' B, [ }$ c, n8 k- \- X1 \6 q
}6 P! t7 k, q4 x5 y# F& `8 p: R
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。. Y2 X% s8 E2 V
这段小代码肯能有两个你需要修改的地方
# r9 R- g" O% e 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
0 O2 h) [- T& f2 `2 r* z/ z 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “$ n* b3 x( A h2 E& ?4 ^0 w* L
|