class Dir

A

Alexander Fleck

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

nobuyoshi nakada

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

Michael Fellinger

--nextPart1397569.6AbZrfHZzG
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--nextPart1397569.6AbZrfHZzG
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBDgulXMdQeL6eBxhIRAl2dAJ4hGsoDG1B7KHjsFwM/aNOa7UhpawCbBvyL
GbDkzgUr6/xwYYuuQiVFXhE=
=GsPo
-----END PGP SIGNATURE-----

--nextPart1397569.6AbZrfHZzG--
 

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

Similar Threads


Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top