此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
- I! M! { H" K8 e. P 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。 ], U- P7 I# F
方式一:; \6 q* F' v( Z @# `3 U9 U% U
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,7 O. g, K4 `; i. s9 y, U' o7 e$ C
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
/ F, C( d* |5 j# M K, }' @# p HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。& B* {+ R6 M K v7 P
方式二:) f6 F* h- @+ X0 m0 b
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- {" F: M, k! { SetTitleMatchMode RegEx
$ g* C, u* ~" ~# z' K return4 O% z3 t+ `# Y" y9 \& G
; Stuff to do when Windows Explorer is open' s- O c5 }+ G ~4 o
;2 }; T: O0 h7 Y
#IfWinActive ahk_class ExploreWClass|CabinetWClass Z0 ?: t- R5 J+ Z3 p
; open ‘cmd’ in the current directory0 ?" h, ^1 F% H: c# `0 [- m3 ~
;
5 d l$ O5 Y9 ^6 o #c::
2 W1 e; t+ O% l OpenCmdInCurrent()
$ I9 N0 h8 ] n+ W# a* |" `* Q return
3 F2 L; [' i8 z8 L8 H #IfWinActive! b l6 D! Q4 S0 H
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.. u& {5 \$ v0 _( W" ~
; Note: expecting to be run when the active window is Explorer.
U3 G% V p9 m V! f ;
' j& Q) t% s2 P1 U OpenCmdInCurrent()
/ b0 C8 `5 M8 V) z5 W% T8 n {
" Y i6 ^) V& Z/ ?; A ; This is required to get the full path of the file from the address bar( H" g' Q: O0 P$ ]+ r) D- K6 \! i; ?
WinGetText, full_path, A6 D* S7 N$ ?; y- x1 W1 N* A2 O
; Split on newline (`n)
4 d2 `/ G9 d: G! W2 ^9 ^ StringSplit, word_array, full_path, `n
6 n) t) L+ E7 w, n4 f ; Take the first element from the array
k4 k& ~, C+ t full_path = %word_array1%4 N: e5 g" l8 Z- F" W! {
; strip to bare address% a; l" ?" I/ m0 E d
full_path := RegExReplace(full_path, “地址: “, “”)# J; C4 Z" i- |' L+ C O
; Just in case – remove all carriage returns (`r)8 l4 t& R/ S% q3 E' u# \1 O
StringReplace, full_path, full_path, `r, , all+ _% [! k6 @4 U$ I
IfInString full_path, \2 v2 ]- p) Y: S
{4 m: ^! V$ `; C+ c) [5 K4 ?
Run, cmd /K cd /D “%full_path%”
( B3 C, E: i5 I3 j1 c }- c- T1 H5 o/ s* \) P. P9 w* S
else3 h; l( @; ~, _
{1 O3 p, X. a/ p K8 o, ~6 \
Run, cmd /K cd /D “C:\ ”% I f# K: k d
}7 {/ I0 i; ~1 P; f6 |
}
$ o, Y3 }0 k. I7 X' Z0 x0 K 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
: w% b8 k E/ q$ `8 e# s+ }( J 这段小代码肯能有两个你需要修改的地方+ }; V1 o$ [9 j0 l
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键$ n( D4 T- ?) O4 i% {
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
. }; o+ @7 ~, A' R7 z |