Skip to content

Instantly share code, notes, and snippets.

@KrzaQ
Last active August 29, 2015 14:19
Show Gist options
  • Save KrzaQ/d267078ec144dccaa98c to your computer and use it in GitHub Desktop.
Save KrzaQ/d267078ec144dccaa98c to your computer and use it in GitHub Desktop.
SearchDir = ARGV[1] || 'D:/mfc/bin'
LogFormat = /^(\d{4})-(\d\d)-(\d\d)-(.+)\.log$/
Name = 'MFC'
OutDir = 'D:/Logs/MFC/'
# do not touch below
Today = Time.new.strftime('%Y-%m-%d')
FileLists = Dir["#{SearchDir}/*.log"].select{ |fileName|
base = File.basename fileName
base =~ LogFormat && base[0...10] != Today
}.group_by{ |fileName|
File.basename(fileName)[0...10]
}.map{ |date, files|
[date, files.map{|fileName| File.absolute_path fileName }]
}.to_h
# p FileLists
FileLists.each do |date, files|
command = '7z a -t7z %{out}/%{date}_%{name}.7z %{files} -r -mx9 -mmt on' % {
:out => OutDir,
:date => date,
:files => files.join(' '),
:name => Name
}
p command
# `#{command}`
files.each{ |fileName| File.delete fileName } if Kernel.system(command)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment