此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。1 Q2 w* r& T( ~* a
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 l" j* f2 l$ t V; `9 n# r0 H
方式一:3 M% B; Q7 x( v0 s5 O S- d
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,8 I/ w, J6 A$ Z$ e$ V+ U
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
; A. c7 ^0 m: x s5 H HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。( k, Q. G8 U" O* `+ l
方式二:
" L9 C8 `6 E: j8 f 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:7 [& E; [9 h) A# ^
SetTitleMatchMode RegEx% r# ~6 V- j; n: Z$ M4 t% h
return
% Q) K ^) S0 l) o9 M ; Stuff to do when Windows Explorer is open
, B# n/ |3 Z- e/ r1 } ;
5 ^2 t K$ J4 y #IfWinActive ahk_class ExploreWClass|CabinetWClass
$ a7 |+ u. g# Q) D! t( ~ ; open ‘cmd’ in the current directory
9 D* a1 B5 v$ T* b# x6 g. M; J ;
! V% R3 O* k5 W- V4 S4 v #c::( T2 z. ~1 g# H
OpenCmdInCurrent()
2 V0 Z) d- d8 ]5 x; e return8 { }) t% u4 x+ w j
#IfWinActive
( C7 N7 Y7 b0 C3 d2 @/ |$ \- C ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.( l- Q3 T7 _$ v; ]
; Note: expecting to be run when the active window is Explorer.# Z$ \) I( W) S; B, W. j7 i
;
% e1 }2 |. J8 {9 Z( D: w: g OpenCmdInCurrent()
3 n( X& R0 z1 I2 c6 t9 G {+ r, n. n& |$ h |/ ]# v5 E
; This is required to get the full path of the file from the address bar
+ h0 @+ N& O5 ~: g WinGetText, full_path, A
; Y1 L% F# u+ k h( \. Z+ s; b B ; Split on newline (`n)" W0 D+ r0 x; P' W6 {
StringSplit, word_array, full_path, `n& v, }0 }6 \6 t W! V
; Take the first element from the array$ ~4 U) C2 f/ ^+ C% A E
full_path = %word_array1%
/ M2 j0 k, D- X ; strip to bare address3 M Z6 D/ D$ I2 @- V- y6 m
full_path := RegExReplace(full_path, “地址: “, “”)
( W( l# F& N6 A. g1 [# R% { ; Just in case – remove all carriage returns (`r): |( O. ?" w8 H, ^$ h
StringReplace, full_path, full_path, `r, , all' ~" G2 }5 Z h9 n7 b- `! Y
IfInString full_path, \/ D$ s* L9 @+ ~! N
{
" {* D c0 @7 d6 J3 l$ X+ a! A0 s Run, cmd /K cd /D “%full_path%”$ \4 P1 E2 e5 [/ E6 Q( A' r6 c/ V5 v* N
}1 [* \# T$ ?5 r. ?, f8 L
else B2 c1 J0 E: b
{
& n/ B" _$ m( {! b& P8 Q B Run, cmd /K cd /D “C:\ ”
9 t/ N6 h+ i' y7 }; Z } A. `4 f5 S l; |3 w# m
}
/ t' q- Q+ ^9 l) ^5 Z& _ 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
4 E& \" v' `9 L 这段小代码肯能有两个你需要修改的地方
$ u7 G& r+ j. O4 N" W* ~ 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
% [& N$ c; B% l4 D 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
8 I& Y9 f# N& `' Q4 F- ~- [2 } |