[批次] 快速cd至特定資料夾

看板EzHotKey作者 (火星人)時間13年前 (2012/06/07 14:56), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
之前寫了一個純ruby版本 可是速度真的太慢了 後來找到在linux上的解法 所以又回來嘗試Windows上的解法 簡單來說,就是可以用"goto.bat {縮寫}"跳到特定資料夾 把下面的程式碼存成"goto.bat" ======== goto.bat ======== @echo off set TEMPFILE=moveto.bat ruby %HOME%\moveto.rb %* > %HOME%\%TEMPFILE% if errorlevel 10 (%HOME%\%TEMPFILE%) else (type %HOME%\%TEMPFILE%) 把下面的程式碼存成"moveto.rb",並把它放在%HOME%裡面 ========= moveto.rb ========= require 'optparse' targets = { 'C' => 'C:\example', 'D' => 'D:\example2', } options = {} OptionParser.new do |opts| opts.banner = 'Usage: moveto.rb [options]' opts.on('-l', '--list', 'Display target list') do |l| options[:list] = l end end if options[:list] targets.each do |name, path| puts '%-7s%s' % [name + ': ', path] end else if targets.include? ARGV[0] puts targets[ARGV[0]][0, 2] puts "cd #{targets[ARGV[0]]}" exit(10) else puts 'Target not found' end end 比如說,你可以用"goto.bat C",就可以跳到C:\example 想要新增資料夾,就在moveto.rb裡面的targets新增 //不懂ruby的話就照著打XD 接著把"goto.bat"放在想要進行快速移動的資料夾 //通常是%HOME%,因為"執行 cmd.exe"會在這個資料夾 這個解法的缺點就是不能在任意資料夾進行快速移動 而且我還找不到可以跳進中文資料夾的方法 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.30.140
文章代碼(AID): #1Fq52FP3 (EzHotKey)