此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
6 u- T( r% C& X" O) d+ X 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
% M$ _. ^5 O1 k) t 方式一:
" I! _$ e3 y) b& @ 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
8 }# z5 ]: d" K4 p9 ^ c 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
C; V$ B% I/ S5 s3 X( r; D3 [" x HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
& m' T1 s8 ~1 t3 n 方式二:
, b* m( I' J7 d0 Y0 _( O, h: e) k9 o# u 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
, V7 |. i& V) C% ~0 F7 R- ^! u SetTitleMatchMode RegEx3 s* F5 T7 v I
return4 l& j! K+ `; u& M
; Stuff to do when Windows Explorer is open2 n3 j3 {1 L6 k" N) c" X
;
- r5 x1 S! O- ` #IfWinActive ahk_class ExploreWClass|CabinetWClass
6 R1 j7 `7 J: w& m* M ; open ‘cmd’ in the current directory% a) Z/ r' a& }& P c3 n8 K T
;
; D# U. f6 P9 N( W X8 o A; O% i R3 V #c::
* v" Y% E( v9 M1 o" J6 l4 R OpenCmdInCurrent()/ E! `" ?" s# I G0 \) O) y
return
" F" |; [2 B; c% A* Z/ Q #IfWinActive
$ p, F8 C6 s8 V ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
, u7 ]2 c9 F; m& m ; Note: expecting to be run when the active window is Explorer.
4 ~* N+ [# M9 E5 p ;" I1 ~) h7 s" i6 z! A1 t( _
OpenCmdInCurrent()
0 x; n; u% u, G' M3 r( A$ d% C; B {
: B1 c! M4 [& C7 n7 m# J( p+ i% Y ; This is required to get the full path of the file from the address bar+ w) T- C9 x( J0 H& B
WinGetText, full_path, A
7 Q2 R7 b9 m {3 ] ; Split on newline (`n): g0 R! d5 Z5 g+ K
StringSplit, word_array, full_path, `n
3 ^8 F) f8 U; w ; Take the first element from the array+ b/ O0 W8 N1 g7 W3 @
full_path = %word_array1%' g6 z8 G4 A- k4 s6 \& f4 u, {; w
; strip to bare address1 q/ `$ w4 k. K
full_path := RegExReplace(full_path, “地址: “, “”)
9 j) u8 x1 d; ]- n+ N ; Just in case – remove all carriage returns (`r)
$ D3 G% M! A# Y2 W StringReplace, full_path, full_path, `r, , all9 d6 v. J i5 w. R- n% a- t
IfInString full_path, \6 t9 ?3 Y m$ O2 w
{. _& H" U8 }# o, d2 A8 A
Run, cmd /K cd /D “%full_path%”
1 L S9 F- e% \" N }* V& O0 V1 M k- V
else
7 M9 b# ]" v2 w: s) g' Z4 f {% p4 z0 Q8 w- u; Y: A1 x
Run, cmd /K cd /D “C:\ ”; c; }, A" `, W2 J
}
( W/ r C$ a: Q }7 K5 a/ F) i# @
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。* _" |- \ p6 \
这段小代码肯能有两个你需要修改的地方) w! S ]# F3 |
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键: p1 z9 q- q* ~1 P7 {+ ~
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
n7 p; j5 }, \. F! J6 { |