此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
; s# C. U J3 f 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
7 U" S) m1 i* k7 T) Y: ` 方式一:
" g9 w7 M4 ~- O# M; j 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
9 h! [( [6 S' J4 E7 `; w 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和' G6 C) }. m: t0 T
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
9 K; K, c# h7 m* @; V& H# E 方式二:8 r3 N' i1 [5 V( w e
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- Y6 ?; W5 h3 {: w8 y SetTitleMatchMode RegEx# W$ y1 H: O2 T/ O0 u4 l6 y! z4 E
return
2 E) S/ L1 f A' {$ v1 t5 i' J ; Stuff to do when Windows Explorer is open! m j0 L3 }% D
;8 l& F/ `7 B5 d! l1 H; G/ s
#IfWinActive ahk_class ExploreWClass|CabinetWClass
" ?0 i# @2 A0 s$ ~& \ ; open ‘cmd’ in the current directory! P& n p- g4 o4 G3 G
;& J# S7 n8 [+ b E5 D
#c::
3 J" v, A% w& I0 e OpenCmdInCurrent()/ z( p1 |, }) w- F0 Q' ^
return8 I/ ?2 F/ ~: X
#IfWinActive& i. H. u) ?& k8 m0 x# m# Z
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.% B; D1 [* ?+ E' J+ h) ~! |5 @* B
; Note: expecting to be run when the active window is Explorer.
3 p$ K! e4 u8 w9 E) ^1 l. C5 Z ;
! _1 U. P q* B5 C9 v2 ]+ Q OpenCmdInCurrent()$ z! v6 E6 |. [) n
{
: A% }# Q- K* s7 }( X; V ; This is required to get the full path of the file from the address bar
5 H' a/ ?* [1 E4 s WinGetText, full_path, A
/ [* E- D! n% `. w d" k ; Split on newline (`n)- Z, w3 K7 m8 ]4 \- P5 X4 @+ s$ Q8 p K; a
StringSplit, word_array, full_path, `n# ~( i) A' L5 |, J2 k- ~
; Take the first element from the array
7 D! K S5 L6 k+ W: I full_path = %word_array1%
x! |. R+ X' \' Z# E* o9 m ; strip to bare address
) M+ F2 L( f" T- E6 T full_path := RegExReplace(full_path, “地址: “, “”)! k! h; k% y% M$ _4 ?* S
; Just in case – remove all carriage returns (`r)
4 S9 ~6 Q6 N/ p# r/ @$ S& n StringReplace, full_path, full_path, `r, , all
6 L6 I' Z0 e, f( G. p IfInString full_path, \
, b+ S. ?* l# j: J8 L: P( n, Q {: ^9 F" {1 Q: I: B3 K9 ]' D
Run, cmd /K cd /D “%full_path%”
0 o) C! m/ S7 P! l+ ?* s; G }
: X; V' l$ I8 o2 I' y else
8 D/ f+ e5 G7 R/ f% C& D( j {
6 m1 |( z4 m$ @$ z1 m5 o7 X Run, cmd /K cd /D “C:\ ” q7 J U' F) ~- b
}# d0 S! @( R8 A
}6 R3 ?' e7 y! t0 p1 f5 e2 a/ T
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。( \- ]. d# h+ ]
这段小代码肯能有两个你需要修改的地方" }3 F8 E1 l9 e A' S
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键/ {/ w7 B2 t- C6 E5 t5 K- W
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
7 X4 I6 L; a: t, Y |