From: Jeffrey Schwab Date: 2006-03-17T09:03:47+09:00 Subject: Re: Delayed File I/O & ZLIB - Any help would be appreciated Brian Corrigan wrote: > Folks, > > Hey Folks, > > I've written a script to generate a list of all files on a machine, > then zip the results. Im going to use it to audit some file servers. > The problem is that the ZIP compression/decrompression isn't working, > but its not what you might think. The script completes, but seems to > not actually write anything. > > Here is a short version that only looks at the C:/temp drive. You can > change this at the top. > > ---Start Code Here-- > require 'find' > require 'csv' > require 'zlib' > > tempfile = "temp.csv" > outfile = "out.zip" > dirname = "c:/temp" > > # Prepare comma-delimited file for writing > CSV::Writer.generate(File.open(tempfile,"w+"), ',') do |csv| > Find.find(dirname) do |f| > csv << [File.dirname(f), File.basename(f), File.mtime(f).to_s] > end > end > > # TEST: View the tempfile to make sure it has data. > # This prints nothing, but the file DOES have info after > # the script completes. Maybe the file isn't written at this point? > p IO.read(tempfile) Are you sure that's not printing anything? It should be print exactly one line of output. > Zlib::GzipWriter.open(outfile) do |gz| > gz << File.open(tempfile).read > end > > Zlib::GzipReader.open(outfile) {|gz| > print gz.read > } > > # The ZIP file can't be extracted with WINZIP. No idea why, but since > # I'll be using another RUBY script for extraction, im not sure that I > care. You didn't zip the file, you gzipped it. I happen to prefer gzip, but if you want zip, this might help: http://rubyzip.sourceforge.net/