Forum: Ruby Parsing files and writing about them . . .

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-04-24 20:05
A number of you all helped me to get to the point of actually being able
to write a RUBY script, period. Now, I'm trying to concatenate all that
I've learned and put it into an iterative script. Here it is. It doesn't
error out, but, it also doesn't do anything! It just executes. I do
believe my regex is legitimate. I want it to parse postscript files and
then pipe information about blank pages in those .ps files to other
files, the ".pageinfo" files.

Thanks.

Dir.chdir("c:/scripts/ruby/temp")
psfiles = Dir.glob('*.ps')
  numberofblanks = []
  blankpages = []
psfiles.each do |psfile|
  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)
    numberofblanks.push($2)
    unless numberofblanks.empty?
      infofile = File.basename(psfile, '.ps')
      File.open("infofile + .pageinfo", "w") do |writetext|
        writetext << "Number of blanks in this PDF:
#{numberofblanks.length}\n"
        << "Blank Pages in This PDF: #{blankpages.join(' ')}\n"
    end
  end
end
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-04-24 22:17
Peter Bailey wrote:
> A number of you all helped me to get to the point of actually being able
> to write a RUBY script, period. Now, I'm trying to concatenate all that
> I've learned and put it into an iterative script. Here it is. It doesn't
> error out, but, it also doesn't do anything! It just executes. I do
> believe my regex is legitimate. I want it to parse postscript files and
> then pipe information about blank pages in those .ps files to other
> files, the ".pageinfo" files.
>
> Thanks.
>
> Dir.chdir("c:/scripts/ruby/temp")
> psfiles = Dir.glob('*.ps')
>   numberofblanks = []
>   blankpages = []
> psfiles.each do |psfile|
>   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)
>     numberofblanks.push($2)
>     unless numberofblanks.empty?
>       infofile = File.basename(psfile, '.ps')
>       File.open("infofile + .pageinfo", "w") do |writetext|
>         writetext << "Number of blanks in this PDF:
> #{numberofblanks.length}\n"
>         << "Blank Pages in This PDF: #{blankpages.join(' ')}\n"
>     end
>   end
> end


Never mind. I actually figured this out myself. I'm so proud. Thanks,
anyway!
This topic is locked and can not be replied to.