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 = Dir.glob(’*.ps’)
blankpages = []
psfiles.each do |psfile|
infofile = File.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) !=0 then
writepage << “%%Blank page from Asura\nshowpage\n”
blankpages = totalnumberofpages.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