此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
0 J; _) H& C3 O1 U& I: D; J# i 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
' o, x: w6 ^! y+ D a1 B5 \0 z; S0 M' H 方式一:9 p2 i% W. l! B
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,% ?) i8 a: G; x
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和% m: Y# a/ C) z
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! W3 j" V5 s J. c8 K0 w- M! I
方式二:
) f) q2 _& B. w0 h2 j$ q% @ 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
% U( t. k/ _* { SetTitleMatchMode RegEx
3 W2 j) J; j: t* S8 S" @, G3 ~ return
- v. L7 g: f/ h: T7 ~4 b4 N ; Stuff to do when Windows Explorer is open
! h6 v. b& H: T4 ]7 r ;
1 N0 v$ j7 U+ u) `( I. n% h #IfWinActive ahk_class ExploreWClass|CabinetWClass# s: e4 s) l5 {4 ~7 H# j5 T& h( B
; open ‘cmd’ in the current directory
4 X' p! P! x @9 V ;. v% v2 N% f4 p, t' N9 z$ \* }
#c::
/ R3 F) ?: v) R9 o& c; i4 o" k- x OpenCmdInCurrent(). U' f, \# m7 c3 N
return' V0 E I# O# X' U8 P0 g
#IfWinActive
8 ~5 Q" C$ t) U; m& C3 I3 w ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
6 G" I8 I3 _2 f$ d- U B, E ; Note: expecting to be run when the active window is Explorer.
, q+ A( [4 J1 X ;. v1 ]. U% W" _+ e' k
OpenCmdInCurrent()
8 q+ B, [# Q7 `' V" ^$ I9 \ {
+ A" d8 [) ?4 K7 A% a: _ ; This is required to get the full path of the file from the address bar
/ [0 o! V7 R( p7 y WinGetText, full_path, A) }6 m5 f7 q% Q
; Split on newline (`n)
1 ?2 G0 T! V; F StringSplit, word_array, full_path, `n" H: a, X" n9 Y/ I6 d2 N; S
; Take the first element from the array+ Y/ p# e& T0 {4 z1 `* W7 X
full_path = %word_array1%
+ R0 `$ `9 ~0 U ; strip to bare address
, q% Z7 Z5 z7 I+ w' S full_path := RegExReplace(full_path, “地址: “, “”)) a: x1 S+ h, D/ r
; Just in case – remove all carriage returns (`r)
$ R) w0 K" A! a( s9 U StringReplace, full_path, full_path, `r, , all) l4 F; Z5 t! [3 y9 V
IfInString full_path, \
& \* [+ Q! w9 j1 N {
4 \) j0 b4 o& F' q8 {. N4 p Run, cmd /K cd /D “%full_path%”0 B _/ v' L2 ?
}) H9 T" A" [! D; ^
else3 d; T+ K3 y7 w$ E
{( v3 [, E7 N G4 r/ e0 g
Run, cmd /K cd /D “C:\ ”
5 ^" z) U5 D, V; Y" {5 ?# w3 z9 h }; F4 p3 k8 U" ~2 Z& q- D
}- g" G1 o }" t' T
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。1 O2 r8 K/ W$ F& l/ t
这段小代码肯能有两个你需要修改的地方8 e8 l3 a& F7 l$ T0 N
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键% R/ B6 L0 U; s1 ]: g
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
" g8 m, y3 R7 Q, I: e( ? |