此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
* y. i+ `+ ?& _ p& ` 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
: R5 L! u/ `; S& m# M1 W5 _ 方式一:
9 B& x) E! ^, {: B 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
* l- Z" S* ]9 H6 I 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
2 y3 r9 j3 u* S% F) [ HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
- M; Q& K/ ` w/ e9 I) D, J) O 方式二:. }8 E2 F, A6 s( F# Y! E. T
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:& T, p# s& k+ f+ H0 C6 V
SetTitleMatchMode RegEx
6 K0 l2 \6 V0 O+ A return
: A1 M, U' ]8 T# w/ B$ q ; Stuff to do when Windows Explorer is open* d7 W) f' F3 a
;
) h- ?8 e/ L' n; P/ g( E1 v) j# K6 ` #IfWinActive ahk_class ExploreWClass|CabinetWClass5 e6 R. ?: c5 Q: T/ W4 F
; open ‘cmd’ in the current directory
/ P- g3 j! x% ^6 B) J& [+ [, B& F ;
' l8 o1 B8 U1 P! d. f #c::
5 T( G& P: n6 U. O0 X8 F o OpenCmdInCurrent()
8 W6 M+ w5 b8 ~ return
3 d+ D$ _8 s2 k* t #IfWinActive
8 }- o# t' [; @ ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
`% j" M& r/ j, R9 Q5 L, e ; Note: expecting to be run when the active window is Explorer.
X. g0 Y/ u0 P# V; g ;
# J4 z8 t3 t- `' k: z OpenCmdInCurrent()
* Y. U' b, d$ F# s3 a$ A9 f" s {* T" m' S" q* c5 {, \2 g
; This is required to get the full path of the file from the address bar4 H/ S7 `. j( N2 r( F
WinGetText, full_path, A
" Z6 d: k( d5 Z4 e ; Split on newline (`n)
" a5 n% T) K: M# ^ StringSplit, word_array, full_path, `n
1 E+ p( M G6 m ; Take the first element from the array5 c9 ~, J* K0 \+ Z. [+ o
full_path = %word_array1%3 M- g2 i4 D+ e. _* M b
; strip to bare address
% P1 t. u' w1 S4 i full_path := RegExReplace(full_path, “地址: “, “”)! ^$ K: G, N' N- Y& _
; Just in case – remove all carriage returns (`r)
) a1 z, {, x! g4 B8 V! Z( d, L StringReplace, full_path, full_path, `r, , all0 f% o1 A" ~6 t# j5 n9 T, `/ z4 c
IfInString full_path, \! x. h$ V5 g: \6 C0 j# X0 x" c; A
{
- t+ V' i. F. j& \1 j Run, cmd /K cd /D “%full_path%”
. u" _$ O, {& C5 `0 e+ Z. l }$ A: J: \! Q7 e4 x. y# I
else& G/ h2 C0 G! ?- W |+ \8 p' i
{1 q a- C8 S( f7 q
Run, cmd /K cd /D “C:\ ”
$ {+ @) n8 G V" @7 n1 |/ } }6 M) k$ \; q5 {7 N2 S
}* M4 n3 o/ C6 T% l3 |7 Q: E+ g8 m6 n
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
& y& W7 U9 V' l( ?: U9 s 这段小代码肯能有两个你需要修改的地方7 E3 S J6 d }: ^
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
7 F( l6 F8 x' v7 [, {4 } 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
, o4 T+ i7 z2 g6 d* |0 W |