First of all, thanks very much psychopath for your posts, really awesome.
I've made a dumb little ruby script that unzips and unrars Pyscho's
file structure that others might find useful here.
The script could easily have been in BASH or anything since it just
unzips and unrars.
It unzips, then unrars with system() to a nominated folder, then moves
the processed folder out the way if the unrar was successful - that way
you can easily see what failed afterwards by what wasn't moved out the
way.
Very little error checking here but the syntax is:
ruby desyco.rb folders destination
folders can be wildcards, destination is where it unrars to. The
folders are moved to a folder called "done" in the parent director, you
need to mkdir that folder before starting.
anyone could easily modify this to also name those files that don't
have the book name using the books folder name
# de-psycho USENET posts
require 'rubygems'
require 'zip'
require 'fileutils'
class Desyco
def process_folders(dirfilter,destination, moveto='done')
Dir.glob(dirfilter).each do |dir|
next unless File.directory? dir
next if dir == moveto
puts "Processing #{dir}"
Dir.chdir dir
files = Dir.glob("*.zip")
files.each do |file|
extract file
end
Dir.chdir("..")
# now unrar whatever came out
files = Dir.glob("#{dir}/*.rar")
successful_unrars = 0
files.each do |file|
successful_unrars += 1 if system("unrar x -o+ '#{file}' #{destination}")
end
# move to done folder if all rar files unpacked OK
FileUtils.mv dir,moveto if successful_unrars == files.count
end
end
def extract file
begin
Zip::File.open(file) do |zip|
zip.each do |zf|
puts "Extracting #{zf.name}"
zf.extract(zf.name) unless File.exists?(zf.name)
end
end
rescue
puts "error unzipping #{file}"
end
end
end
Desyco.new.process_folders(ARGV[0],ARGV[1])
|
|