list files in a directory

Feb 26, 2011 at 4:44pm
Hello! I need to list the contents of a directory into an array..
I tried using readdir but it kept returning errors :S

1) can you give me some instruction on listing contents in a directory?
2) Is there a way to echo system commands into a variable/array?

thanks

EDIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 

#include <dirent.h>

...

int main () {
  readdir("/home");

...

  return 0;
}
Last edited on Feb 26, 2011 at 4:53pm
Feb 26, 2011 at 6:55pm
RTFM.
readdir expects a DIR * and return a dirent * that is an entry in the directory.
opendir returns DIR * with a path as parameter.
Don't forget closedir.

2) system is evil http://www.cplusplus.com/forum/articles/11153/
Feb 27, 2011 at 3:16am
code example please? :D
Feb 27, 2011 at 3:17am
Im rusty on c/c++ so.. yeha :S
Feb 27, 2011 at 3:22am
and i did read the man.. it isnt very clear though
Feb 27, 2011 at 12:41pm
http://www.cplusplus.com/forum/unices/3480/#msg14680

You should try searching the forum. This has been answered many times.
Last edited on Feb 27, 2011 at 12:43pm
Feb 27, 2011 at 5:55pm
hmmk sorry for my noobdulance :P I got it working :D
Topic archived. No new replies allowed.