Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [rake] excluding dirs with FileList

Reply
Thread Tools

[rake] excluding dirs with FileList

 
 
Joel VanderWerf
Guest
Posts: n/a
 
      08-01-2005

How can I construct a FileList that excludes dirs? Not a particular
directory, but _any_ directory?

I had hoped that #exclude could be passed an object whose #=== method
returned true for a dir (using File#directory?). But #exclude tries to
turn its argument into a string and build up a regex.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


 
Reply With Quote
 
 
 
 
Ezra Zygmuntowicz
Guest
Posts: n/a
 
      08-01-2005
--Apple-Mail-9-678961618
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed


On Jul 31, 2005, at 6:13 PM, Joel VanderWerf wrote:

>
> How can I construct a FileList that excludes dirs? Not a particular
> directory, but _any_ directory?
>
> I had hoped that #exclude could be passed an object whose #=== method
> returned true for a dir (using File#directory?). But #exclude tries to
> turn its argument into a string and build up a regex.
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>


require 'find'

file_list = []
start_path = "/path/to/directory/" <= the dir to start recursing
from.

Find.find(start_path) do |file|
file_list << path unless test(?d, file)
end

p file_list

This works unless I misunderstand what you are trying to do. See
$ ri test for more info.
HTH-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper

509-577-7732


--Apple-Mail-9-678961618--


 
Reply With Quote
 
 
 
 
William James
Guest
Posts: n/a
 
      08-01-2005

Joel VanderWerf wrote:
> How can I construct a FileList that excludes dirs? Not a particular
> directory, but _any_ directory?
>
> I had hoped that #exclude could be passed an object whose #=== method
> returned true for a dir (using File#directory?). But #exclude tries to
> turn its argument into a string and build up a regex.
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


list = []
Dir.glob( "*" ){ |f|
list << f unless File.directory?(f)
}
p list

 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      08-01-2005
On Monday 01 August 2005 05:39, Ezra Zygmuntowicz wrote:
> On Jul 31, 2005, at 6:13 PM, Joel VanderWerf wrote:
> > How can I construct a FileList that excludes dirs? Not a
> > particular directory, but _any_ directory?
> >
> > I had hoped that #exclude could be passed an object whose #===
> > method returned true for a dir (using File#directory?). But
> > #exclude tries to turn its argument into a string and build up a
> > regex.
> >
> > --
> > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

>
> require 'find'
>
> file_list = []
> start_path = "/path/to/directory/" <= the dir to start recursing
> from.
>
> Find.find(start_path) do |file|
> file_list << path unless test(?d, file)
> end
>
> p file_list
>
> This works unless I misunderstand what you are trying to do.


Sorry if this sounds like bad advertisement, but with Rant
the same looks like:

file_list = sys["/path/to/directory/**/*"].no_dir

Perhaps someone wants to integrate it into Rake.

HTH,
Stefan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to return filelist? Lasse Edsvik ASP .Net 1 10-04-2004 12:54 PM
Filelist -> Droplist? Lasse Edsvik ASP .Net 1 10-04-2004 08:41 AM
Rake FileList not working? T. Onoma Ruby 5 08-25-2004 11:38 AM
Help with Rake and FileList jim@freeze.org Ruby 3 08-23-2004 02:06 PM
FileList and FileFilter and regular expressions P.Hill Java 6 11-18-2003 03:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57