Forum: Ruby class Dir

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C76a52a7216844fe0e462e3d39ac97e4?d=identicon&s=25 Fleck (Guest)
on 2005-11-22 09:55
(Received via mailing list)
Hi,
what' s the best way to detect if a Dir entry is a directory or file? I'
m doing a Dir.foreach blabla |x|.
I' m trying to use 'directory?', but it doesn' t work the way I use it.

Thanks,
Alex.
04a56914cc09f0858d3fca2bf4cbde34?d=identicon&s=25 nobuyoshi.nakada (Guest)
on 2005-11-22 09:59
(Received via mailing list)
Hi,

At Tue, 22 Nov 2005 17:52:23 +0900,
Alexander Fleck wrote in [ruby-talk:166951]:
> what' s the best way to detect if a Dir entry is a directory or file? I' m doing a 
Dir.foreach blabla |x|.
> I' m trying to use 'directory?', but it doesn' t work the way I use it.

Dir.foreach yields just basenames.  You'll need to prefix the
directory name to them.

Dir.foreach(blabla) {|x| x = File.join(blabla, x); p x if
File.directory?(x)}

Or, Dir.glob(File.join(blabla, "*/")) returns an array of the
directories.
C76a52a7216844fe0e462e3d39ac97e4?d=identicon&s=25 Fleck (Guest)
on 2005-11-22 10:39
(Received via mailing list)
Thanks,
it works. I just offered names to the 'directory?'-method.
86e33dee4a89a8879a26487051c216a8?d=identicon&s=25 m.fellinger (Guest)
on 2005-11-22 10:51
(Received via mailing list)
Dir.new('./').entries.partition {|i| File.directory?(i))}
=>	[
	[".", "..", "log", "src", "conf", "_darcs", "public", "script",
"templates"],
	["README", "run.rb.save", "run.rb"]
	]


Am Dienstag 22 November 2005 09:52 schrieb Alexander Fleck:
This topic is locked and can not be replied to.