Listing directories within a directory

M

mattcarpenter

Heya,

I'm in need of a way to list the directories inside of a directory
using C++ and the linux C libraries. I've tried readdir() and
scandir(), however those return the entire contents of a directory --
including the files within. I would like just a list of the
directories. Is there a way to do this without downloading another
library like boost? Thanks!

Regards,
Matt Carpenter
 
R

Rolf Magnus

Heya,

I'm in need of a way to list the directories inside of a directory
using C++ and the linux C libraries. I've tried readdir() and
scandir(), however those return the entire contents of a directory --
including the files within. I would like just a list of the
directories. Is there a way to do this without downloading another
library like boost? Thanks!

Well, your question is off-topic here. You should better ask it in a linux
programming newsgroup.
Having that said, the answer to your question depends on what you want to do
with the subdirectories. Do you just want to open them again? Then just try
opendir() on everything you get. If it's not a directory, you'll get
ENOTDIR back. If you don't want to open them, you can use stat() to test
whether an entry is a directory or not.
 
M

mattcarpenter

Sorry about posting in the wrong newsgroup, I'll be sure to direct my
quesiton towards the appropriate one next time. Your suggestion is
exactly what I needed however. Thanks!

Regards,
Matt
 

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

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top