此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。( [" a7 z3 w! E0 P* D
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
: C; \0 L6 o2 T, X$ q 方式一:
1 _% Y* e3 D* |+ M0 \6 O 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
' T7 Z2 n: \' v& X 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
8 a' Y! d* L4 H! m8 j; }0 R HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。8 r; t0 W) L' |
方式二:
' [- A! S) }+ y9 W 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下: j; P- F# D, g0 ?) b
SetTitleMatchMode RegEx
9 M& X! T& a; R! E8 t return
- W1 e1 k; ^# s/ y1 L# c ; Stuff to do when Windows Explorer is open
3 S2 r7 R, [1 k+ X ;2 X1 [6 T7 M3 \; H- e; I+ n( B6 ^
#IfWinActive ahk_class ExploreWClass|CabinetWClass
2 x. L% t* k, T ; open ‘cmd’ in the current directory
4 X: O1 X. u/ G ;7 o- s' ~1 _, ]
#c::, F; q; P- V% F
OpenCmdInCurrent()
3 K" n- P" o: @$ _ return2 k1 j6 O+ [1 G$ X P5 H
#IfWinActive
- \, u9 G8 ^/ O s% u ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
s b6 P0 h6 j. s2 @$ @9 z5 T O, }* U ; Note: expecting to be run when the active window is Explorer.' x, F0 B% _6 \' V% p2 ?
;
v( h5 @# h+ ^& z7 T OpenCmdInCurrent()' R0 j6 m( i; I' \2 l6 q
{0 R* k! m0 j! y. U
; This is required to get the full path of the file from the address bar
" I' S, `: @9 p. T0 c( G WinGetText, full_path, A' g5 {: D# z/ B% o2 i) N
; Split on newline (`n)
% z8 z* q% Q$ z) }% F7 n0 x StringSplit, word_array, full_path, `n
L3 o) i& K' H ; Take the first element from the array& ^7 s3 A* r; W8 @" P
full_path = %word_array1%
+ p. |" }/ n5 o# L9 y ; strip to bare address
, c2 U5 a2 L$ N) l# { D7 y7 G full_path := RegExReplace(full_path, “地址: “, “”) Y) X9 G: [* G$ O
; Just in case – remove all carriage returns (`r)2 |4 a2 F( G; L" ` h
StringReplace, full_path, full_path, `r, , all/ P+ |# ]; q# Q# X+ S
IfInString full_path, \
$ c; `8 f9 d. j' _- G+ n, y8 n; c { f) X/ F/ J- X1 H, U- ?) o9 {
Run, cmd /K cd /D “%full_path%”
" D/ g, o: k3 G) O! R }2 ?( L7 ^6 v% X/ Q* b% c2 i# a2 ?2 y
else8 \& ?. B5 p9 z1 B+ ^2 l
{+ P4 Z2 g8 |1 Y9 p' o! y
Run, cmd /K cd /D “C:\ ”4 d9 F) B' u% h( W7 T" R- i
}3 u% n* o! t, B
}
3 h; y; A r& E9 \* i8 o8 r 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
" }0 R2 A R# Z$ _6 B$ c 这段小代码肯能有两个你需要修改的地方- N6 a% P9 f+ n8 V
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
# ^) P4 s! y8 W$ X 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “% o7 r9 p2 q6 K* G6 R8 Q1 _9 A
|