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!!

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/

s/newfile/new_file

···

On Tue, 12 Oct 2004 17:39:20 +0900, Brian Schröder <ruby@brian-schroeder.de> wrote:

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/

Aron Stansvik wrote:

s/newfile/new_file

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/

Oh, thats true. And also I did not follow my own advice to use underscores. So s/oldfiles/old_files/ too.

regards,

Brian

···

On Tue, 12 Oct 2004 17:39:20 +0900, Brian Schröder > <ruby@brian-schroeder.de> wrote:

--
Brian Schröder
http://ruby.brian-schroeder.de/