[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

search file in a directory

Li Chen

10/21/2006 6:54:00 PM

Hi folks,

Which built-in method is used to search a file in a directory and all
its children directory?

Thanks,

Li

--
Posted via http://www.ruby-....

9 Answers

Robert Klemme

10/21/2006 8:36:00 PM

0

Li Chen wrote:
> Which built-in method is used to search a file in a directory and all
> its children directory?

As always, there are more ways, depending on what you want to do. For
simple searching of a file by name Dir is easiest. Find is more
appropriate for tasks that have to deal with every file etc.

http://ruby-doc.org/core/classe...
http://ruby-doc.org/stdlib/libdoc/find/rdoc/...

Regards

robert

Li Chen

10/21/2006 10:33:00 PM

0

Thank you for you all,

Li

--
Posted via http://www.ruby-....

EB

10/22/2006 2:55:00 PM

0

Li Chen wrote:
> Hi folks,
>
> Which built-in method is used to search a file in a directory and all
> its children directory?

Yup, I was looking for something similar, a simple way
to get the functionality of the unix "find" command.

I was motivated by the slow search facility under XP. Not
sure if ruby might be faster, but it made me curious how
I would specify a file to be found in a directory tree.

As a newbie I am still not quite familiar with all of the
facilities or libraries, maybe it's obvious :-)

eb

Li Chen

10/22/2006 4:54:00 PM

0

EB wrote:
> As a newbie I am still not quite familiar with all of the
> facilities or libraries, maybe it's obvious :-)
>
> eb

Me, too. I need to spend some time to read the documentation and figure
out how to write the script.

Li


--
Posted via http://www.ruby-....

Robert Klemme

10/22/2006 5:13:00 PM

0

Li Chen wrote:
> EB wrote:
>> As a newbie I am still not quite familiar with all of the
>> facilities or libraries, maybe it's obvious :-)
>>
>> eb
>
> Me, too. I need to spend some time to read the documentation and figure
> out how to write the script.

Didn't you see my last reply? Do we have a gateway problem again?

robert

Li Chen

10/22/2006 5:32:00 PM

0

Robert Klemme wrote:
>
> Didn't you see my last reply? Do we have a gateway problem again?
>
> robert


Yes if you mean the information on the previous post:
....
http://ruby-doc.org/core/classe...
http://ruby-doc.org/stdlib/libdoc/find/rdoc/...

As I reply to EB I need time to read the doc and write the script by
myself.

Li



--
Posted via http://www.ruby-....

Robert Klemme

10/22/2006 6:24:00 PM

0

Li Chen wrote:
> Robert Klemme wrote:
>> Didn't you see my last reply? Do we have a gateway problem again?
>>
>> robert
>
>
> Yes if you mean the information on the previous post:
> ...
> http://ruby-doc.org/core/classe...
> http://ruby-doc.org/stdlib/libdoc/find/rdoc/...
>
> As I reply to EB I need time to read the doc and write the script by
> myself.

No, there was another posting. I realize it is in another thread:
http://groups.google.com/group/comp.lang.ruby/msg/afcb58...

Regards

robert


Li Chen

10/22/2006 9:45:00 PM

0

EB wrote:

>
> Yup, I was looking for something similar, a simple way
> to get the functionality of the unix "find" command.
>
> I was motivated by the slow search facility under XP. Not
> sure if ruby might be faster, but it made me curious how
> I would specify a file to be found in a directory tree.
>
> As a newbie I am still not quite familiar with all of the
> facilities or libraries, maybe it's obvious :-)
>
> eb


Hi EB,

I think Robert kindly provies a pretty neat script which is what I want.
I am not sure if you also need a similar one like this, which searches a
directory and all children directory for the file specified.

Li

###
require 'find'

path='I:/Common/xxx/Notebooks/Flow/OT1/OTI-4'

file_number = 0

Find.find(path) do |f|

puts f if File.file?(f) && f=~/\.\d+$/
# print out the file with format xxx.001 xxx.002...
file__number+=1

end

puts file_number


--
Posted via http://www.ruby-....

James Gray

10/24/2006 5:15:00 PM

0

On Oct 22, 2006, at 12:15 PM, Robert Klemme wrote:

> Do we have a gateway problem again?

We took some pretty drastic measures when we addressed the last
Gateway issue and haven't seen a thing since. I think we have it
pretty locked down now.

James Edward Gray II