此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
/ y4 @. z, \2 h# l) f2 J 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。& ^$ P2 D6 K0 {4 }- m1 O+ G
方式一:
& `# E2 c+ @( R9 ?! e K E( I 在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
5 A& S" B% y5 @" i% Y 去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和3 s N: A/ ^. x L9 X( }# k
HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。1 W1 V( [1 ]. N, z
方式二:1 F& o6 {) d: T
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
# ~: d2 N) t2 j) E& i# B" D& x& k SetTitleMatchMode RegEx
3 ?5 P. V9 q& N7 y' i% _* i: T return% s* `) R# M& e+ V
; Stuff to do when Windows Explorer is open4 m2 G/ f9 O/ B" U7 {0 N' D! Y
;
- j$ Z+ f+ }* A #IfWinActive ahk_class ExploreWClass|CabinetWClass0 o8 C$ ?; t4 r; K8 q3 _
; open ‘cmd’ in the current directory' S; g1 v2 a& |7 a; r/ |
;
) @' o+ T3 R* n0 m( M K #c::7 a# r0 x1 J- V9 A/ W6 v3 O, W, w
OpenCmdInCurrent()
3 L; @7 ^: w# ~# }9 B) [& p return
S$ N" k' K. R% _% u* r #IfWinActive0 o3 B3 Z0 Y9 r; n$ o) u& D K
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
0 ^3 H7 E" p3 J/ o& B7 p ; Note: expecting to be run when the active window is Explorer.
! r J; |* E5 W# Z; h ;
+ j* d7 k6 N% I* q3 v OpenCmdInCurrent()5 C7 _/ P5 x0 C4 _ o: s# ~
{
* s9 t: f5 m4 J) n5 e9 x ; This is required to get the full path of the file from the address bar' V" A4 m/ u4 b" v7 I0 ~" l
WinGetText, full_path, A3 p; d3 B) ]- W6 I) ?& [# @
; Split on newline (`n)! r \3 ~4 R% j2 @) p
StringSplit, word_array, full_path, `n
1 T. J. u* @7 H* j0 w# f" C ; Take the first element from the array7 N9 B+ x$ J4 X& E0 G
full_path = %word_array1%
/ i+ _& y' ]- Z% s6 g& i4 R ; strip to bare address
) X1 H* }6 n$ O& S3 b full_path := RegExReplace(full_path, “地址: “, “”)
" f$ c; W- j- r ; Just in case – remove all carriage returns (`r)
+ Z7 ^6 p% ^. j' ?9 c: W8 ^ StringReplace, full_path, full_path, `r, , all
: ?$ R" `* n6 c4 I; b IfInString full_path, \$ n- J% e4 P" |2 B0 ?; ~
{1 m1 f% C; t8 G2 u" e; g
Run, cmd /K cd /D “%full_path%”
2 o( [6 R2 F/ Y) l5 \( d }
) E- U$ q/ O9 w3 L# M( q else
: y2 k+ p6 Z$ N! ]+ M, b {7 |7 A$ }8 l ~1 h+ h8 t8 ]
Run, cmd /K cd /D “C:\ ”
+ |0 z. l: ~9 w4 V9 v }7 Z/ P6 B/ Z; v5 X( y: M
}
6 W4 _2 x8 S$ r% |6 o" I. k 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
6 t- U0 M0 c# L* E- C0 l/ w 这段小代码肯能有两个你需要修改的地方' \( D. c' k ^" e9 L9 J- U
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键6 {7 |& l) `. S# S& S2 w9 p# v
2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
9 z" m( Q% B: Q4 m& D4 w |