--------------030005070302020309060404 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Peter Bailey wrote: > Hello, > Can someone look at my code below? I have a RUBY debugger that indicates > to me that when I get to the 2nd "File.read" below, all of the previous > variables are wiped away. I'd like to know why that is. I need to do 2 > searches, 2 scans, in the same files. It doesn't seem to like my 2nd > pass. As a result, nothing past my 2nd File.read occurs. > > Thank you. > > -------------------------------------------------------------------------------- > require 'FileUtils' > Dir.chdir("c:/scripts/ruby/temp") > psfiles ir.glob('*.ps') > > blankpages ] > > psfiles.each do |psfile| > infofile ile.basename(psfile, '.ps') > File.open(psfile, "a") do |writepage| > File.read(psfile).scan(/\%\%Pages: (\d{1,5})\n/) do > totalnumberofpages 1 > #If the page count is odd, then, add a blank to make it an even > page count. > if (totalnumberofpages.to_i % 2) ! then > writepage << "\%\%Blank page from Asura\nshowpage\n" > blankpages otalnumberofpages.to_i + 1.to_i > end > end > > File.read(psfile).scan(/\%\%Page: [(\d)()]+ > (\d{1,5})\n\%\%PageBoundingBox: > \d{1,5} \d{1,5} \d{1,5} \d{1,5}\n\%\%PageOrientation:/) do > blankpages.push($1) > File.open(infofile + ".pageinfo", "w") do |writetext| > writetext << "Number of blankpages in this PDF: > #{blankpages.length}\n" << > "Blank Pages in This PDF: #{blankpages.join(' ')}\n" > end > end > end > end > > I think part of the issue here is that you open the file for writing, then do a read on the same file. Looking at IO.read: Opens the file, optionally seeks to the given offset, then returns /length/ bytes (defaulting to the rest of the file). read ensures the file is closed before returning. But you have already opened the file. So, your structure above looks something like: File.open(psfile) { #opens psfile File.read(psfile) { #opens psfile } #closes psfile File.read(psfile) { #opens psfile } #closes psfile } #closes psfile I'm not sure if that is the problem or not. -Justin --------------030005070302020309060404--