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 Corrigan ---------------------------
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 Corrigan <brian.corrigan@mm-games.com> 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 Corrigan > --------------------------- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060316/1a977e60/attachment.html
You know.. I realized that after I wrote the email. My mistake.. But, same results?? My output is "" Nil Any other ideas? Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Chris Hall Sent: Thursday, March 16, 2006 6:28 PM To: rails@lists.rubyonrails.org 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 Corrigan <brian.corrigan@mm-games.com> 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 Corrigan --------------------------- _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/2cfec9a7/attachment-0001.html
Ok, well I figured out part of the issue. The CSV file isn''t being written before the Zlib call. If I break this up into two scripts, the first that writes the file, the second that zips it, things work. Any idea why the CSV file wouldn''t be saved when the block ends? Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Brian Corrigan Sent: Friday, March 17, 2006 9:18 AM To: rails@lists.rubyonrails.org Subject: RE: [Rails] File Auditing with rails - File I/O issue You know.. I realized that after I wrote the email. My mistake.. But, same results?? My output is "" Nil Any other ideas? Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Chris Hall Sent: Thursday, March 16, 2006 6:28 PM To: rails@lists.rubyonrails.org 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 Corrigan <brian.corrigan@mm-games.com> 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 Corrigan --------------------------- _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/d7c5de53/attachment-0001.html
the problem is you aren''t closing the csv file try this ... tmpcsv = ''temp.csv'' File.open(tmpcsv, ''w+'') do |file| CSV::Writer.generate(file) do |csv| Find.find(dirname) do |f| csv << [File.dirname(f), File.basename(f), File.mtime(f).to_s] end end end ... On 3/17/06, Brian Corrigan <brian.corrigan@mm-games.com> wrote:> > Ok, well I figured out part of the issue. The CSV file isn''t being > written before the Zlib call. If I break this up into two scripts, the > first that writes the file, the second that zips it, things work. > > > > Any idea why the CSV file wouldn''t be saved when the block ends? > > > > *Brian Corrigan* > *Operations Manager* > > *MGAM Systems, Inc.* > 1 Broadway Place > Schenectady, NY 12305<http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Schenectady%2C+NY+12305&country=us> > > brian.corrigan@mm-games.com > > tel: > fax: > mobile: > > 518-881-1121 > 518-881-1128 > 518-727-6652 > > > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *Brian Corrigan > *Sent:* Friday, March 17, 2006 9:18 AM > > *To:* rails@lists.rubyonrails.org > *Subject:* RE: [Rails] File Auditing with rails - File I/O issue > > > > You know.. I realized that after I wrote the email. My mistake.. But, > same results?? > > > > My output is > > "" > > Nil > > > > Any other ideas? > > > > *Brian Corrigan* > *Operations Manager* > > *MGAM Systems, Inc.* > 1 Broadway Place > Schenectady, NY 12305<http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Schenectady%2C+NY+12305&country=us> > > brian.corrigan@mm-games.com > > tel: > fax: > mobile: > > 518-881-1121 > 518-881-1128 > 518-727-6652 > > > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *Chris Hall > *Sent:* Thursday, March 16, 2006 6:28 PM > *To:* rails@lists.rubyonrails.org > *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 Corrigan* <brian.corrigan@mm-games.com> 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 Corrigan > --------------------------- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/ca2d1392/attachment-0001.html
Yep, that was the right direction, but I had to instantialize the File object and close it manually after the block.. Here''s the working code for anyone who may need it in the future :-) csvfile = File.open(tempfile, ''wb'') CSV::Writer.generate(csvfile) do |csv| # For each drive find all files, write out to file drives.each do |d| if d.isReady.to_s=="true" and d.shareName.to_s == "" then Find.find(d.driveLetter+'':/temp'') do |f| if !File.directory?(f) then csv << [hostname, File.dirname(f), File.basename(f), File.mtime(f).strftime("%Y-%m-%d %H:%M:%S")] end end end end end csvfile.close Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Chris Hall Sent: Friday, March 17, 2006 11:27 AM To: rails@lists.rubyonrails.org Subject: Re: [Rails] File Auditing with rails - File I/O issue the problem is you aren''t closing the csv file try this ... tmpcsv = ''temp.csv'' File.open(tmpcsv, ''w+'') do |file| CSV::Writer.generate(file) do |csv| Find.find(dirname) do |f| csv << [ File.dirname(f), File.basename(f), File.mtime(f).to_s] end end end ... On 3/17/06, Brian Corrigan <brian.corrigan@mm-games.com> wrote: Ok, well I figured out part of the issue. The CSV file isn''t being written before the Zlib call. If I break this up into two scripts, the first that writes the file, the second that zips it, things work. Any idea why the CSV file wouldn''t be saved when the block ends? Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Brian Corrigan Sent: Friday, March 17, 2006 9:18 AM To: rails@lists.rubyonrails.org Subject: RE: [Rails] File Auditing with rails - File I/O issue You know.. I realized that after I wrote the email. My mistake.. But, same results?? My output is "" Nil Any other ideas? Brian Corrigan Operations Manager MGAM Systems, Inc. 1 Broadway Place Schenectady, NY 12305 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Sch enectady%2C+NY+12305&country=us> brian.corrigan@mm-games.com <mailto:brian.corrigan@mm-games.com> tel: fax: mobile: 518-881-1121 518-881-1128 518-727-6652 ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Chris Hall Sent: Thursday, March 16, 2006 6:28 PM To: rails@lists.rubyonrails.org 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 Corrigan <brian.corrigan@mm-games.com> 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 Corrigan --------------------------- _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/6d23de44/attachment-0001.html
really? hmm, the way File.open works is that if a block is given, the file will be closed when the block terminates. plus you get the added benefit that if an exception occurs, the file will be closed automatically. irb(main):001:0> File.open(''test.txt'', ''w+'') do |file| irb(main):002:1* file << "this is a test" irb(main):003:1> end => #<File:test.txt (closed)> On 3/17/06, Brian Corrigan <brian.corrigan@mm-games.com> wrote:> > Yep, that was the right direction, but I had to instantialize the File > object and close it manually after the block.. Here''s the working code for > anyone who may need it in the future J > > > > > > csvfile = File.open(tempfile, ''wb'') > > CSV::Writer.generate(csvfile) do |csv| > > # For each drive find all files, write out to file > > drives.each do |d| > > if d.isReady.to_s=="true" and d.shareName.to_s == "" then > > Find.find(d.driveLetter+'':/temp'') do |f| > > if !File.directory?(f) then > > csv << [hostname, File.dirname(f), File.basename(f), > File.mtime(f).strftime("%Y-%m-%d %H:%M:%S")] > > end > > end > > end > > end > > end > > csvfile.close > > > > > > *Brian Corrigan* > *Operations Manager* > > *MGAM Systems, Inc.* > 1 Broadway Place > Schenectady, NY 12305<http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Schenectady%2C+NY+12305&country=us> > > brian.corrigan@mm-games.com > > tel: > fax: > mobile: > > 518-881-1121 > 518-881-1128 > 518-727-6652 > > > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *Chris Hall > *Sent:* Friday, March 17, 2006 11:27 AM > > *To:* rails@lists.rubyonrails.org > *Subject:* Re: [Rails] File Auditing with rails - File I/O issue > > > > the problem is you aren''t closing the csv file > > > try this > > > ... > > tmpcsv = ''temp.csv'' > File.open(tmpcsv, ''w+'') do |file| > > CSV::Writer.generate(file) do |csv| > > Find.find(dirname) do |f| > > csv << [ > > File.dirname(f), File.basename(f), File.mtime(f).to_s] > > end > > end > > end > > ... > > > > On 3/17/06, *Brian Corrigan* <brian.corrigan@mm-games.com> wrote: > > Ok, well I figured out part of the issue. The CSV file isn''t being > written before the Zlib call. If I break this up into two scripts, the > first that writes the file, the second that zips it, things work. > > > > Any idea why the CSV file wouldn''t be saved when the block ends? > > > > *Brian Corrigan* > *Operations Manager* > > *MGAM Systems, Inc. * > 1 Broadway Place > Schenectady, NY 12305<http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Schenectady%2C+NY+12305&country=us> > > brian.corrigan@mm-games.com > > tel: > fax: > mobile: > > 518-881-1121 > 518-881-1128 > 518-727-6652 > > > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *Brian Corrigan > *Sent:* Friday, March 17, 2006 9:18 AM > > > *To:* rails@lists.rubyonrails.org > > *Subject:* RE: [Rails] File Auditing with rails - File I/O issue > > > > You know.. I realized that after I wrote the email. My mistake.. But, > same results?? > > > > My output is > > "" > > Nil > > > > Any other ideas? > > > > *Brian Corrigan* > *Operations Manager* > > *MGAM Systems, Inc. * > 1 Broadway Place > Schenectady, NY 12305<http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1+Broadway+Place&csz=Schenectady%2C+NY+12305&country=us> > > brian.corrigan@mm-games.com > > tel: > fax: > mobile: > > 518-881-1121 > 518-881-1128 > 518-727-6652 > > > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *Chris Hall > *Sent:* Thursday, March 16, 2006 6:28 PM > *To:* rails@lists.rubyonrails.org > *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 Corrigan* <brian.corrigan@mm-games.com> 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 Corrigan > --------------------------- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/053113c3/attachment-0001.html