[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to get and compare file lists in directory?

nkb

10/12/2004 8:01:00 AM

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


3 Answers

Brian Schröder

10/12/2004 8:39:00 AM

0

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-sch...


Aron Stansvik

10/12/2004 4:03:00 PM

0

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-sch...
>
>



Brian Schröder

10/12/2004 6:39:00 PM

0

Aron Stansvik wrote:
> 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-sch...
>>
>>
>
>

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

regards,

Brian
--
Brian Schröder
http://ruby.brian-sch...