此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
. C# N3 x3 z4 N$ M 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- f6 e$ ]. ], E. f; M 方式一:
5 w) s+ z/ a' }3 x% T+ h" X 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,$ x$ T6 [- ~% \. O$ }
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和: _1 i9 y* ^! J* F9 b4 u- M5 j
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
8 d# {/ e t' i; C0 G1 ]* W 方式二:! ^: v t1 K5 b$ v5 k! W
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:7 g9 l+ i! { {# e8 Q2 w% {- }
SetTitleMatchMode RegEx
* f# }7 C& X. w2 g return
$ d5 \+ m- X# P ; Stuff to do when Windows Explorer is open
[2 j6 A4 n4 b ;
! x* N6 o6 N6 A+ q" u5 w0 m. G #IfWinActive ahk_class ExploreWClass|CabinetWClass4 w. _7 Y+ V5 T$ n9 M
; open ‘cmd’ in the current directory
& H) J/ {8 _% J. @, U" T9 c8 t ;0 C1 M2 z2 h1 }; u$ ]5 E+ ]' g
#c::" I- r5 j" S& J- i4 t' y; q
OpenCmdInCurrent()7 i, d* I) B9 _/ T5 ]$ R, S
return
2 I, g, o: _5 n R6 z/ P #IfWinActive
" B R9 y" s3 y9 K% @ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
# {) @/ W8 l5 w( s: u5 M ; Note: expecting to be run when the active window is Explorer.
0 u9 Z* I3 ?4 K ;
7 H) S L( Q8 Y% v m7 K7 A* g6 d OpenCmdInCurrent()
- V! Y0 l7 ^+ r7 @; ? {
3 ?6 J3 J: H) J J+ Z! b5 X ; This is required to get the full path of the file from the address bar
4 N9 c* q, x1 |( X* W, ^& f5 J3 U WinGetText, full_path, A+ n1 \! X4 C; |9 G
; Split on newline (`n)1 L: g, S8 W) e8 L: l' B1 m
StringSplit, word_array, full_path, `n; z M7 U" r1 a' \' O; A* L
; Take the first element from the array
5 y& `# H" w1 [' ?' w full_path = %word_array1%/ C# ~: m+ A ?: p& Q3 k. y
; strip to bare address
+ w0 }% P- L$ v: x1 n) g/ s full_path := RegExReplace(full_path, “地址: “, “”)
, r$ H: ^# I2 p) H, k ; Just in case – remove all carriage returns (`r)
6 B( \. V# s T StringReplace, full_path, full_path, `r, , all9 a, P$ ]9 S7 O: X7 [, Z
IfInString full_path, \
' |8 e" B% [. m" x {: U0 @1 V$ }5 g9 _0 N' X! D' d
Run, cmd /K cd /D “%full_path%”
1 q9 y* u* Z# S& V7 W; ~0 x9 B }. N' [2 @. D2 N/ u
else& M5 q+ u' K: I+ l' c3 g
{
4 p/ X) ^9 }2 l# X( _8 x+ ? Run, cmd /K cd /D “C:\ ”' b* [( W! r; f8 |' G+ X
}
# M! _. s5 e" l9 M. x+ m5 M }
4 u1 f, G* \/ C4 r6 h3 [ 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
& s* K8 h. j1 G8 N2 x1 Z 这段小代码肯能有两个你需要修改的地方+ J# j* s) h( V/ [1 h I2 A) y3 Q" b
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键7 X' N6 u; R* v
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “# \' o' ~# ~# K/ o5 P
|