此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
& f1 n/ h+ H# } 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
: }! ]. \4 Z' Z" z- @- Z 方式一:
! q0 W+ C$ O9 x+ m/ k: B' a 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表," B; R, I! G4 m
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
$ Y( u" v8 V: G) j$ A HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。9 s: n/ ]6 W5 q( u3 R$ u1 B/ N
方式二:
" h; d$ c% O- \, G0 H& s+ D& o8 C 用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
) o: k( S+ r0 D5 ?2 | SetTitleMatchMode RegEx3 ^! n6 J+ x2 F! w, J4 H/ D) n
return5 r3 _" ]0 f8 p" {: w
; Stuff to do when Windows Explorer is open
9 d: N: }2 a" u- d ;
6 [8 n* w, w, M0 x' {6 Y6 a9 ` #IfWinActive ahk_class ExploreWClass|CabinetWClass
0 B6 e: y( ^& a9 z: S' P ; open ‘cmd’ in the current directory; q% C: Q6 s+ P7 a4 k' ?, \- ?
;! h$ o' ~9 f7 W
#c::
y! U: {: C4 t X! } OpenCmdInCurrent()+ m3 h+ }- Q) u$ I
return
8 M& r: ?% [1 j# } #IfWinActive
6 o0 `& Y9 H, v# ` ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
/ H3 C* l ~, d% ?5 e8 U ; Note: expecting to be run when the active window is Explorer.
% h5 \$ q( s$ w6 c! C ;
+ @+ m8 `3 i( }" G& _5 E OpenCmdInCurrent()
( p8 a) P5 u# V; M% Y {
* {5 x1 x# `5 i) S: e ; This is required to get the full path of the file from the address bar
. n, k9 `3 q* M' V5 F. F7 u WinGetText, full_path, A3 S8 f, r8 V/ e: U
; Split on newline (`n)
) x$ t/ A) f7 U' [! f StringSplit, word_array, full_path, `n
9 z1 w7 R5 {2 K ; Take the first element from the array
3 M+ y, s% ^0 r! v9 f2 m2 l# @6 c full_path = %word_array1%* b. m2 A' M- B6 q" F
; strip to bare address
: H, C6 C9 W. y0 I5 O! f1 l6 P full_path := RegExReplace(full_path, “地址: “, “”)
- {) U4 ]: J! g- j W ; Just in case – remove all carriage returns (`r), l+ h* l; Z1 L& s- {6 O6 @7 e
StringReplace, full_path, full_path, `r, , all
3 [& ]% z7 Z0 N* D! L0 `" u4 u! h IfInString full_path, \8 ~, y! ~4 @& J8 A: h
{( \( E1 a J* i6 E9 i9 w& ]
Run, cmd /K cd /D “%full_path%”
8 K# }- x: d6 @! {3 n0 U" [ }
; G* r2 V3 @, n. C: ` l else) g: U# k- N0 k" F" a
{- |/ R# G' ?& l; A$ P G
Run, cmd /K cd /D “C:\ ”
{5 c# M( _. X1 b" q6 B, h- } }
+ i, v7 ]$ i: {) s" Q }
( {: q5 A5 ?# I/ W7 C 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。( d! r: i9 g* D3 z ?' L
这段小代码肯能有两个你需要修改的地方
- C6 R& G; D; C1 U: ^3 f) q/ i& L- T2 [ 1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键# f R* [( E. E5 l: V
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
1 s1 Y8 ~3 C) q5 v% Q |