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
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
ezra@yakima-herald.com
509-577-7732
···
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
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
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
···
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.