此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。, X5 Q% w+ n# N, Q$ I+ E
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。8 z! P9 X A A6 O% X9 j$ b ?
方式一:4 z! ?. b- Y8 A- k' u
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
& m' g ^0 j( l8 j5 ^ 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和6 v3 d5 y" n! l0 B* |4 K7 D
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
9 k2 B# t! B8 \! @% y 方式二:
- b0 a- S$ ?! E' d) I3 R& C& ^ 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:7 i2 m! [6 E7 t! E* {. c
SetTitleMatchMode RegEx
2 E6 T1 n/ z6 D return
$ A( {7 C+ P' B& t ; Stuff to do when Windows Explorer is open) M8 j/ K% y" d- R8 @1 m$ U
;
! {" \. q, p5 t #IfWinActive ahk_class ExploreWClass|CabinetWClass
9 y! ]: |" H' Q! _ ; open ‘cmd’ in the current directory) e' b6 u) Q' E$ P# k
;
9 ~6 E5 x7 L- H, q* N) x# w( P #c::9 U/ T9 q, z) J9 `9 S$ R
OpenCmdInCurrent()
( m4 q& L3 e4 o$ t) @ return9 Y7 O5 D' h3 P8 ~) F6 e% W
#IfWinActive3 r* ?6 ]- Z! i% ~ j1 b
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
, K+ Z- R6 U& B$ C8 p* H* E* ^' K% D ; Note: expecting to be run when the active window is Explorer.7 Z5 ^, }/ o3 t
;
& m8 X7 H& Y2 l& I/ E6 I OpenCmdInCurrent()
+ l. g/ l- ~7 p; Z {
( F) W. N. v6 e ; This is required to get the full path of the file from the address bar
0 C& J8 M6 u. @( T' d: n4 m# f WinGetText, full_path, A. j/ ]! ?- I: k* H& Y S. U9 u
; Split on newline (`n)
5 ~# {/ S/ r/ [' _4 W+ f% w& t StringSplit, word_array, full_path, `n! {0 D* f6 A* y# e+ x+ s
; Take the first element from the array: c+ p t$ x! _; t% E2 w* {
full_path = %word_array1%
$ d" v& K+ c- }: l9 n8 I' ]5 S1 ? ; strip to bare address5 B# ]# E) K1 G- I2 [6 t- u. X+ \
full_path := RegExReplace(full_path, “地址: “, “”)
- r8 f" x, J6 G9 [ _ ; Just in case – remove all carriage returns (`r)* M9 L/ s9 W: z. N7 O* x, F) Q7 b
StringReplace, full_path, full_path, `r, , all
$ L2 G: }# c; Y; Z( L* K0 Q/ Y IfInString full_path, \
+ M" G, I9 a9 _) H7 Z% F {* n2 ^0 z( j5 w7 a5 d
Run, cmd /K cd /D “%full_path%”
- c) @. b( m3 p3 T4 y; [5 N } r( z, \' p; `9 @
else
) g. j- V& ^; ^- b; a {: {/ U ]3 |0 k; p
Run, cmd /K cd /D “C:\ ”5 o: q: l, A5 k# r% y3 O
}4 \: _5 M! [7 a5 m' m
}: v6 E" R( @+ H& R% I
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
% \9 V" s/ s/ g 这段小代码肯能有两个你需要修改的地方# S# i: T: c' ^# V- W4 z. I
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
5 Q1 Q; M3 ^3 L3 _ 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “3 t* b5 I7 h- N! N% a$ i6 W! G
|