[rake] excluding dirs with FileList

  • Thread starter Joel VanderWerf
  • Start date
J

Joel VanderWerf

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

Ezra Zygmuntowicz

--Apple-Mail-9-678961618
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed


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.

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
(e-mail address removed)
509-577-7732


--Apple-Mail-9-678961618--
 
W

William James

Joel said:
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.

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

Stefan Lang

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top