From: John Joyce Date: 2007-07-24T22:50:03+09:00 Subject: Re: Boolean question. File here but not there. On Jul 24, 2007, at 8:09 AM, Peter Bailey wrote: > Hi, > I'm tryiing to determine that, for every TIFF file I have, is there a > corresponding PDF file, and, if there isn't, then, notate that in the > log. If there is a PDF file, then, don't log it. So, the resulting log > should show me a bunch of PDF files that I'll need to create, so > that I > have a PDF for every TIFF I have. This script below seems to be > listing > every single PDF file as not being there, even though the file's > there. > Whew. Obviously, I must have something wrong with my Boolean > logic. . . > . > > Thanks, > Peter > > > ... > list.each do |tifdir| > pdfdir = tifdir > Dir.chdir("L:/tiff/cdtiff/#{tifdir}") > Dir.glob("*.tif").each do |tiffile| > pdffile = File.basename(tiffile, ".tif") + ".pdf" > tifthere = File.exists?("L:/tiff/cdtiff/#{tifdir}/#{tiffile}") > pdfnotthere = !File.exists?("L:/pdf/single/#{pdfdir}/#{pdffile}") > if tifthere && pdfnotthere > File.open("E:/logs/pdfnotthere.txt", "a") { |f| f.print > "#{pdfdir}/#{pdffile} not there\n" } > end > end > end > -- > Posted via http://www.ruby-forum.com/. > Try using two Dir.globs one for an array of tiffs and one for an array of pdfs then use Array#include? to compare one array's elements to the other array by basename only. create an array of matches or an array of non matches or both use Array.collect to create the new array of pairs. While you do that delete them from the previous arrays. Output the 3 arrays and you have your pairs and non pairs.