How to get and compare file lists in directory?

I wrote a script that compares files in two directory trees using an
external program 'diff'. Here's a snippet of what I did. It might help
you.

···

#----------------------------------------
# Get entries from the two paths
  d1 = Dir::open(d1path).entries
  d2 = Dir::open(d2path).entries

# I'm doing this on Windoze so I can change all to uppercase...
  d1.each{|x|x.upcase!}
  d2.each{|x|x.upcase!}

# You might also want to reject some other files,
# maybe everything but your *.rb files?
  d1.reject! {|x|
    /^\.{1,2}$/ =~ x # ignore the directories '.' and '..'
  }
  d2.reject! {|x|
    /^\.{1,2}$/ =~ x # ignore the directories '.' and '..'
  }

# Compare two arrays using vector math on the arrays (d1 - d2)
# I just print the results but you could change the block to call
# some other method.
printf("Here are the files found in %s but not in %s.\n",
         d1path, d2path)

  (d1 - d2).sort.each { |x|
    printf " %s\n", x
  }
#----------------------------------------

I'm still a bit crude with Ruby. If someone can 'golf' it, that would be
cool.

Drew

-> -----Original Message-----
-> From: nkb [mailto:nkb@pacific.net.sg]
-> Sent: Tuesday, October 12, 2004 4:01 AM
-> To: ruby-talk@ruby-lang.org
-> Subject: How to get and compare file lists in directory?
->
->
-> Hi.
->
-> I've a directory with a long list of files (e.g. *.rb,
-> *.txt, etc.). All
-> my ruby files are named like 00001.rb, 00002.rb up to
-> 05000.rb or so.
-> What I am really interested is to get the ruby file list and
-> compare it
-> with an existing list. And if this new list has additional files, I
-> would invoke another program with just the integer part of
-> the file as
-> the arugment. (i.e. runmyprogram (5000) instead of
-> runmyprogram (05000.rb))
->
-> My ruby knowledge allows me to write up to here:
-> directory = Dir
-> puts Dir.pwd
-> puts Dir.entries(Dir.pwd)
->
-> Could anyone help or point me to how to get set the rest of my
-> requirement? Thanks!!
->