此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
5 }/ l3 K( V+ z& \0 T( A2 _ 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
9 K6 F/ E, m \* [4 a6 T 方式一:2 ~1 l$ H6 t0 `7 w% r
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
& P+ d2 v. d; X4 ~0 e# ~0 d 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
# M8 W1 z/ b: n HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
- @5 H/ q* U6 }; g; R( H$ E 方式二:
. f% r& h9 A7 L9 n! ^- i. o g( d 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:! k- A* z8 v& f! W
SetTitleMatchMode RegEx
4 v6 t, ~5 {/ W, f return
3 r0 |: a$ m! Z) P6 e ; Stuff to do when Windows Explorer is open
! \( n9 X7 p3 j ;
. Y* ~6 @' ], r) v5 {1 b+ @8 y #IfWinActive ahk_class ExploreWClass|CabinetWClass- l: m3 }5 X0 Y
; open ‘cmd’ in the current directory
\& C: z2 C* G5 t. O8 ~2 p. H ;& j( H; ?8 H: Z1 [, t n
#c::0 q$ o/ j' H3 U" S' w- Z
OpenCmdInCurrent()
. O/ e6 W N, P2 S- j return
5 ~7 L: `, ~+ I. \' m- S #IfWinActive
: K/ ^: h5 D, u2 H/ B ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
# }3 s# t* n5 V* ] e' r" V ; Note: expecting to be run when the active window is Explorer.
2 g0 Y: R# z- T" V7 B5 u+ G; k8 B ;
! Z w7 t) A1 V OpenCmdInCurrent()
3 s; ?( i4 H$ y8 Y& s3 q {- e1 c2 J% p6 a W1 x
; This is required to get the full path of the file from the address bar
6 e3 o7 F: O A* [; p3 Z+ l WinGetText, full_path, A/ p: T' G& G8 Q
; Split on newline (`n); h8 S: p) D5 x* E% V+ j
StringSplit, word_array, full_path, `n1 G) W' L& W9 E6 b7 t% Z
; Take the first element from the array- I A# ^# I! _. `. w1 Q: t
full_path = %word_array1%8 r* r" Z% K: A% j- R N5 h3 A" G
; strip to bare address
, w! u9 K8 q) o) ^" }. Y full_path := RegExReplace(full_path, “地址: “, “”)
" c# R; e; k0 q. s1 E4 V: Q6 F5 t ; Just in case – remove all carriage returns (`r)
: D! P3 s; Y3 l; F& ? StringReplace, full_path, full_path, `r, , all9 P8 H$ X. H6 l; |0 T
IfInString full_path, \* c( q/ c: _8 x& `% E
{7 Q! l" p& ]* s5 y2 v
Run, cmd /K cd /D “%full_path%”7 W6 ^1 [, a. p+ Q6 q
}5 _! g+ I4 Q/ c! a
else/ |8 m, I& \$ D) f" c, R1 C% n
{
( T E/ q6 f6 i; Z5 | Run, cmd /K cd /D “C:\ ”
0 ]! B. O' ]/ I/ |: L }/ P. e" r' _+ L4 W3 I% c2 [) q
}. \+ e4 v" d$ h2 e4 U, ?- N( ?
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
z. L, k" |$ r, B% t( Q+ @ 这段小代码肯能有两个你需要修改的地方- P: t* U9 f+ P+ H9 k" M- R7 h- n
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键6 w' V5 v# Y |
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
! g) F& c* Z D G' d |