q2ch - ログ掃除スクリプト
2月20日の日記で書いたq2chのログのゴミ掃除スクリプトをRubyで書いてみた。試してみたけど短い間に結構ゴミが溜まるんだなぁ、それだけ速度の速いスレッドを見てるってことか。。。
っていうか、q2chは0.3.27y16を使用してるのだけどもっと新しいバージョン(あるのか?)ではゴミが出ないようになってるんだろうか?
余談、このスクリプトはemacsで書いたけど少々重いのをガマンすれば結構使い易いかも。TABの移動量が2カラムなのだけは何とかしたいんだけど。
#!/usr/bin/env ruby Navi2chDir = "/home/zaurus/Documents/navi2ch" if !FileTest.exist?(Navi2chDir) print "#{Navi2chDir} is not exist\n\n" exit(1) end if !FileTest.directory?(Navi2chDir) print "#{Navi2chDir} is no directory\n\n" exit(1) end Dir.foreach( Navi2chDir ){|srvDir| next if srvDir =~ /^\.\.?$/ srvPath = Navi2chDir + "/" + srvDir next if !FileTest.directory?(srvPath) print "check... " + srvDir + "\n" Dir.foreach( srvPath ){|boardDir| next if boardDir =~ /^\.\.?$/ boardPath = srvPath + "/" + boardDir next if !FileTest.directory?(boardPath) print "... " + boardDir + "\n" list = Hash.new(nil) noInfoDir = false Dir.foreach( boardPath ){|file| infoPath = boardPath + "/info" if !FileTest.exist?(infoPath) print "...... no info directory\n" noInfoDir = true break end next if file =~ /^\.\.?$/ if file =~ /^(\d+)\.dat/ list[$1] = true end } break if noInfoDir Dir.foreach( "#{boardPath}/info" ){|file| next if file =~ /^\.\.?$/ if list[file].nil? print "...... Delete " + file + "\n" File.delete("#{boardPath}/info/#{file}") end } } }