For those looking for a quick solution for opendir readdir
Reading files in a directory using @c++:
It seems that "ls" causes some problems so if you read around enough @C++ developers tell you to use @opendir and @readdir. I'm posting this here mainly because I never found a code solution that was in one piece, so I'm adding this code for some quick public searching. Code:
#include <sys/types.h> |
Hi, nice program! Just a few notes:
1) Your program is missing main() 2) Code:
DIR *Dir = new DIR(); 3) You shouldn't mix stdio with iostream |
Or to really cheat:
(note no error checks) edit: except it doesn't really work properly, oops need to use glob as well, I'll fix it tomorrow. Code:
#include <stdio.h> Code:
found : 29 |
@millgates - Thanks I didn't know about the stdio vs iostream issues.
@bigearsbilly - Thanks you have a better solution and can run on Centos 5 and Cygwin. This line of code can compile and run on cygwin, however on Centos 5 it can't compile. Code:
DIR *Dir = new DIR(); |
Don't thank me too soon, it doesn't quite work.
If one does say '*.c' and there's no match still it will print '*.c' so it needs a further glob to work properly. |
All times are GMT -5. The time now is 09:32 AM. |