此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。+ Y. D( h& Q+ p
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。4 c; ?8 o; s& i/ Q* w* o. X6 c& |5 T
方式一:
$ i2 [3 c4 S0 I9 |& ` 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' o; k2 w& i/ a ^0 M# b$ x; ]
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
9 A* ~9 S/ N$ L' o! D HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。4 L2 J* v% H; A. o( J' k8 O4 ~
方式二:: a) I) M" a l0 [8 @4 v+ w+ Y* c
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:4 l& u7 U- u- n" g3 p; D
SetTitleMatchMode RegEx
% x- \, L8 _6 C7 p; U( ^2 E; t return, U K9 t/ w3 ~$ \: L. U9 @0 S
; Stuff to do when Windows Explorer is open
" x% A- k- d" F/ a* c ;: J/ F Z) z" y
#IfWinActive ahk_class ExploreWClass|CabinetWClass
8 Y: H) l9 W; \! c) h- P9 E ; open ‘cmd’ in the current directory
6 g; J: p& Z# W( v( u ;* q9 E2 h! _3 D4 L- d/ m9 J
#c::2 S: |# k8 s" d5 D, F
OpenCmdInCurrent()" E! w/ H4 u' s! _5 |
return
! n8 \3 v8 g& X& l- t" v' \ #IfWinActive
( Y2 C/ [4 {6 T ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.5 ~) E3 G5 J" a# J
; Note: expecting to be run when the active window is Explorer.! k4 T) e6 l5 ]+ n
;$ _5 C) ]5 l% _ L2 G
OpenCmdInCurrent()/ C. H& G- Q( {# s
{
3 b( V2 ], f. D9 e/ Z* S; q2 ? ; This is required to get the full path of the file from the address bar
- L) H3 R' s. ~ WinGetText, full_path, A
1 D/ s: `' l5 f# i6 W4 i a ; Split on newline (`n)
, [1 j6 \3 V0 ~; d9 T1 n/ k StringSplit, word_array, full_path, `n4 J8 o7 g4 L" j) [# w' |
; Take the first element from the array
$ G+ K& Q6 \1 O- {2 _* x1 s0 U7 L full_path = %word_array1%
) `& T! r- r; B0 F6 A; [ ; strip to bare address; k6 }+ n% i5 Y6 D8 a L
full_path := RegExReplace(full_path, “地址: “, “”)
$ z* d$ D2 W/ x; S6 O. G) b* j8 _" c6 l ; Just in case – remove all carriage returns (`r)8 h6 g0 ?! y9 {4 ^8 T5 h
StringReplace, full_path, full_path, `r, , all
8 ]! t9 ]5 T% J' G7 b9 n: { IfInString full_path, \6 C' c, Q1 e: K: ^5 y: s: M0 {8 T# Y
{
5 E& Z& @ k% B) U Run, cmd /K cd /D “%full_path%”% [: \9 i0 n$ ^( D- O
}
+ L$ a# {7 \$ ~$ n# U else8 e' e" K: N8 P& S3 b% A
{
* N# _: Q/ \+ B0 o* | Run, cmd /K cd /D “C:\ ”
: A$ l5 P7 Y1 p# ^ }
+ K* i1 x4 x0 t1 D }
& _2 s7 [& ~ G* b1 l$ C 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
4 Y6 T, g+ X% A2 S; n 这段小代码肯能有两个你需要修改的地方( d0 Q: p9 Y% s- v! @
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
* e2 t& Y+ c" Z, a! s 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “! Q$ n$ e+ ?* `- U& d, H0 X
|