Connecting Tech Pros Worldwide Forums | Help | Site Map

Listing directories within a directory

mattcarpenter@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
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


Rolf Magnus
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Listing directories within a directory


mattcarpenter@gmail.com wrote:
[color=blue]
> 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![/color]

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.

mattcarpenter@gmail.com
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Listing directories within a directory


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

Closed Thread