From: "Brian Schröder" Date: 2004-10-12T17:39:20+09:00 Subject: Re: How to get and compare file lists in directory? nkb wrote: > 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)) Please note, that in ruby you have to but the argument list with the method call. ie run_my_program(5000). Also for methods snake case is used, so for better readablity enter "_" between the words. > > 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!! > Warning: Typed directly into the email: oldfiles = (File.exist?'old_rb_files.lst') ? File.open('old_rb_files.lst'){|file|file.read.split("\n")} : [] new_files = Dir['*.rb'] - old_files new_files.each do | new_file | puts "Do something with #{newfile}" end File.open('old_rb_files.lst', 'a+') do | file | if /(\d+).rb/ =~ file run_my_program($1.to_i) end regards, Brian -- Brian Schr�der http://ruby.brian-schroeder.de/