此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
) b g9 l# N( ]. _; Q3 C- ~ 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
3 ~+ o" M: v0 ?, ]- `& N 方式一:
; Y' L6 J9 Q H. F' n5 F- I 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' }4 W! V2 _2 |4 M. i
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和 p9 J$ g9 X+ |& K3 ^ @* ~; }& ^
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。' w1 j3 W( D5 _( A/ [9 j. R" {
方式二:: C3 E( A; c- J% B1 b, t* r
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
% J9 F! X/ ^) x, J/ j, T SetTitleMatchMode RegEx
0 {6 ~! L3 ]+ Z0 e$ K7 @# M return7 S8 G- t( g6 i& m2 X1 R
; Stuff to do when Windows Explorer is open) H3 A; q- r- x' E3 N. _* t
;
% @7 M, x! ~6 x! q* D: C- f& [ #IfWinActive ahk_class ExploreWClass|CabinetWClass' ?2 f c- [5 r
; open ‘cmd’ in the current directory$ P3 {( H6 C+ u9 l2 N" |: }+ L4 q
;
0 S% p' f2 d( ~9 } #c::
" k' X! U. k) y0 S OpenCmdInCurrent()
* D/ Q) j( x k3 @0 t return
c! G# z( K* e4 H) x g #IfWinActive
& h/ T( V: o/ }6 h: n8 K ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
; p; }& |3 Z8 O- [/ F1 \- c9 m ; Note: expecting to be run when the active window is Explorer.. N1 [# R5 P# K6 E0 D
;; E1 C% {; ]. T, v, s0 |' e
OpenCmdInCurrent()( S% ^3 U1 o( V |2 f6 i# u* y2 l
{7 ~4 ~- ]2 q# F& y
; This is required to get the full path of the file from the address bar
: W/ ?( O5 i" y4 s. I& |( h8 I WinGetText, full_path, A) P4 g5 G& l) \$ u
; Split on newline (`n)) d- _. d7 i9 k9 u% a% R0 w' C
StringSplit, word_array, full_path, `n
* ^5 V8 p; B3 V! `2 b ; Take the first element from the array
" q5 g5 ?( f. ]2 v! s( F full_path = %word_array1%7 C# e$ a8 ~" A4 M+ R* h* ?1 i
; strip to bare address5 O7 S. r3 Y& R% q" E( Y
full_path := RegExReplace(full_path, “地址: “, “”)
5 Z6 r: p5 o- a' }" I# L ; Just in case – remove all carriage returns (`r)
3 Y5 t4 P' m8 S q: @8 ~ StringReplace, full_path, full_path, `r, , all
" }! h1 s* p1 f7 P' K IfInString full_path, \ b. R6 I, ?/ u3 b
{
( B* f5 Z: S, x" k. ]) b Run, cmd /K cd /D “%full_path%”. C, H4 l6 G+ p! i
}) c4 y# o9 D' q" S8 H3 P J
else5 I5 [" ^! }) Y Y2 C
{8 P! y' K2 m; V7 T* B
Run, cmd /K cd /D “C:\ ”
! o2 E! H7 X- k }
9 J/ D7 s" c" u5 | }
) ~- o( \2 V- R9 z 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。9 y( F0 r n! t( {4 ~1 q( Q Z
这段小代码肯能有两个你需要修改的地方& G" h" R$ j6 o- R4 @: [& b
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
' |* q1 A$ Y+ S- `: g F 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “! f% a2 U& E: Z% F, `
|