# RE: File Auditing with rails - File I/O issue

**URL:** <https://www.ruby-forum.com/t/re-file-auditing-with-rails-file-i-o-issue/83161>\
**Category:** Rails\
**Created:** [March 17, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/re-file-auditing-with-rails-file-i-o-issue/83161 "2006-03-17T15:18:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [March 17, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/re-file-auditing-with-rails-file-i-o-issue/83161/1 "2006-03-17T15:18:56Z")

</div>

You know… I realized that after I wrote the email. My mistake… But,  
same results??

My output is

“”

Nil

Any other ideas?

Brian C.  
Operations Manager

MGAM Systems, Inc.  
1 Broadway Place  
Schenectady, NY 12305  
\<[Yahoo Search - Web Search](http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch)  
enectady%2C+NY+12305&country=us\>

removed\_email\_address@domain.invalid [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

tel:  
fax:  
mobile:

518-881-1121  
518-881-1128  
518-727-6652

* * *

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Chris H.  
Sent: Thursday, March 16, 2006 6:28 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Rails] File Auditing with rails - File I/O issue

I think you might want to try

outfile = “out.gz”  
…  
Zlib::GzipWriter.open(outfile) do |gz|  
gz.write(File.read(tempfile))  
end

also, gzip != zip hence why winzip can’t do anything with the resulting  
gzipped file. I wouldn’t know if winzip supports gzip compression or  
not. the extension for a gzipped file is typically .gz.

Chris

On 3/16/06, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hey Folks,  
I’ve written a script to generate a list of all files on a machine,  
then zip the results. I’m going to stick a web front end on it, and use  
it to audit some file servers. The problem is that the ZIP  
compression/decompression 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)  
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.

* * *

## Brian C.
