此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
1 ^* V7 m8 D# c 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- c4 M4 t. M- u% i/ L$ K 方式一:. g6 M' o2 |! {. g" {
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表, R# \8 p) _( _% t) L
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
& g! ^1 i, Q: l8 s/ L1 N HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。9 R; h' S- @% ?" S; |" p
方式二:
* b! K$ u! |" K- f 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:6 R6 C Z& d5 M% \& T
SetTitleMatchMode RegEx
0 G) {2 O7 S; o- }% o return
! O3 d! p/ s. R G: k' b% K ; Stuff to do when Windows Explorer is open
1 H9 r% }! c8 I7 L8 q ;' N7 a; H* `& r( q4 Z3 \, b
#IfWinActive ahk_class ExploreWClass|CabinetWClass! B6 P2 F5 _; j3 x1 e! t
; open ‘cmd’ in the current directory2 l4 w' {1 j4 I
;; \+ [: Z9 H# E1 n( M3 Q
#c::6 ~. K9 \3 w4 }/ A
OpenCmdInCurrent()# e1 Z* [ U7 r
return! C' c7 O7 d- V' ]
#IfWinActive d- l& m3 s* i9 B, \# @
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
5 C) B1 u5 ~1 N9 X ; Note: expecting to be run when the active window is Explorer.
5 @! B- i- D" Q+ Q ;) k# Q$ H: D9 o. s
OpenCmdInCurrent(); k( u8 V- r7 G9 ^% w$ a; t# C
{
2 x$ P8 O" j- W$ V) z2 w" ^ ; This is required to get the full path of the file from the address bar
/ J; Q. H9 C8 Z5 `5 f WinGetText, full_path, A8 F Y% X) s. Q5 m
; Split on newline (`n)3 V( o6 d- m. }8 A9 k! b
StringSplit, word_array, full_path, `n
+ ~( [& I/ M1 q. [8 U/ ~7 J) o ; Take the first element from the array- a3 l1 d) P0 d2 T5 W" L
full_path = %word_array1%
% s2 M# m& W5 V( {& j: z( x ; strip to bare address7 W5 q5 Q- b$ h# }; t1 t; A
full_path := RegExReplace(full_path, “地址: “, “”)
3 ]8 Q- `7 {, z& |( L6 l% ` ; Just in case – remove all carriage returns (`r)8 x' N8 T T$ {6 V' ~
StringReplace, full_path, full_path, `r, , all
9 S# V; S# X6 k. c* o/ X IfInString full_path, \$ s3 G4 ^$ A V) g7 e/ w$ J1 t6 h
{' z, P; S/ Q1 ]( `0 b
Run, cmd /K cd /D “%full_path%”7 q; g e% Z4 t$ q
}+ n! n1 H# J, @$ |+ l! L' {% t
else f* a. z d/ X0 O/ a
{
4 D- j9 P. l3 ?1 ?1 ^: Y Run, cmd /K cd /D “C:\ ”
: p2 T5 b2 }, M: N- d `* O }
7 J6 `0 ~# y7 _# ]+ `* P }' v r* U6 ^2 _. n7 W( M
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。5 j5 Z, q6 m- t4 m) v6 i( O' L
这段小代码肯能有两个你需要修改的地方0 ]2 [' [3 X# z) s
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键2 M V7 ]+ I5 x2 {; I0 U% T
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “! m2 x. l. r, k( J, Y! U
|