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.
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.
Hi,
At Tue, 22 Nov 2005 17:52:23 +0900,
Alexander F. 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.
Thanks,
it works. I just offered names to the ‘directory?’-method.
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 F.:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs