此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
) X4 a. U6 b x' l v" O" c, l 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- k" q! g3 f( i$ O 方式一:4 A; H! v; ^1 u" o* j' C' w! F, P8 p
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
/ H& k6 s9 R- o9 @# ]8 q 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
- H1 ?: ~2 H" \. L- x# Q HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。* t6 w2 l# k- X1 R a$ e
方式二:+ j$ I6 L6 W4 y" x! n' A
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
' G3 ?6 `5 a) W. k4 E! N" n SetTitleMatchMode RegEx; u! L9 z8 f* A- ]) v: k. x
return3 F* ~& F% J8 y# ^. @2 `* o
; Stuff to do when Windows Explorer is open
9 ?+ B( V' A- b! w4 @$ D( E ;
: s3 j% d2 E! }! \2 r #IfWinActive ahk_class ExploreWClass|CabinetWClass
# P- p" g! s" p' }% U* }: \ ; open ‘cmd’ in the current directory/ @# A$ d: M# ^* g0 P
;* W' x1 i; }# W: a; q
#c::
% P$ M4 E1 e6 \; b OpenCmdInCurrent()
/ c6 L- R$ t2 D O. ? return
. a P$ l0 Y/ h' Q; U6 v5 z #IfWinActive; e) Y% J* U7 i* }6 P/ k
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.6 [4 y y& U$ r; y0 w
; Note: expecting to be run when the active window is Explorer.
. u5 A' P, F3 s ; O8 p9 J c# R( H: x. M
OpenCmdInCurrent()
( E. M% n2 _" ? M! g, k {0 i% e' o4 O s8 s2 m$ Z' p' |
; This is required to get the full path of the file from the address bar7 R9 T0 o2 E1 F+ u/ Q2 x4 [
WinGetText, full_path, A
! ?$ Q% w+ A7 \9 J7 o X ; Split on newline (`n)! F$ m' y9 D, J7 }* N' l% e; Z
StringSplit, word_array, full_path, `n* \! f9 T1 t, V4 \" _! X3 }1 I
; Take the first element from the array% V* G6 _7 y1 |
full_path = %word_array1%; V6 b/ w5 x) j
; strip to bare address
, t7 N5 R; Q3 H8 f- v full_path := RegExReplace(full_path, “地址: “, “”)' F" R" C* U) N4 H' W! z
; Just in case – remove all carriage returns (`r)0 r5 u) ]8 Y K. o
StringReplace, full_path, full_path, `r, , all: r3 D; O6 j; B4 w) v+ Y
IfInString full_path, \5 y6 J7 |8 g# k( n' @& t3 K% U
{
" r3 \* a6 m% r7 @: _4 d Run, cmd /K cd /D “%full_path%”! A& A# x$ U4 d& i3 R
}
3 q9 S5 T1 d6 b9 c$ m0 r9 Z else: C$ i n8 U% r0 F
{
+ c; B5 {/ {) l Run, cmd /K cd /D “C:\ ”
% p1 l/ [0 } u+ o* D/ B$ J+ Y }
- f( C# `8 }( Z" Z7 V i }* A) L% O' ?7 N# f2 y1 f" A
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
- G8 |" C* O* {6 ^# J; Q4 B0 c 这段小代码肯能有两个你需要修改的地方5 e. G' I: y' V
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
+ u! x3 U- j0 k. _: t; f 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
. y7 E% ^% [! c% U; l |