I made a new project that has to open a folder using DIR *
DIR * directory=openDir(...); // openDir is a function returning DIR * after it was opened
than to make a new folder in it, so far so good
and now i have to run through the folder entries using
while ((ent=readdir(directory))){ do stuff ; }
but it wont get into the loop.

and if i add this code AFTER the previous code it works and i get into the loop

DIR *dirr=openDir(path);// same openDir function from above

i do get into the while loop.

any ideas?

edit: (another question)
and what can i do in order for the readdir to avoid subdirectories? ( avoiding the new folder i just created in it)

Edited by Despairy

4 Years
Discussion Span
Last Post by Ancient Dragon

Here is a code snippet I wrote some time ago, maybe it will help you with your question. As for the sub-directory question, see the example in my code snippet -- you have to test for them.

The code snippet was written in c++, so just ignore the code you may not understand and concentrate on the loops.

Edited by Ancient Dragon


well it is easier for me to understand c++ because that's what we are programming in usually.
eventualy I just used the macros S_ISREG for just handling the regular files , so done with that.

but I don't understand why I have to open the DIR* twice.
I do it once to check if the folder exists
and I add a sub folder . <---------------------------- could this be the problem? I dont think so...
so I want to continue using it but DIRENT wont get a thing but NULL.
then I reopen it and it works fine

well i sent the exercise already but still if you know whats wrong I'd be happy for an answer

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.