# Parsing files and writing about them . .

**URL:** <https://www.ruby-forum.com/t/parsing-files-and-writing-about-them/58682>\
**Category:** Ruby\
**Created:** [April 24, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/parsing-files-and-writing-about-them/58682 "2006-04-24T20:05:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 24, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/parsing-files-and-writing-about-them/58682/1 "2006-04-24T20:05:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 24, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/parsing-files-and-writing-about-them/58682/2 "2006-04-24T22:17:21Z")

</div>

Peter B. 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!
