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
mkdir(path,permissions);
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
while(ent=readdir(dirr)){stuff}

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)

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.

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
thanks

You need to post the code you wrote if you expect anyone to answer your questions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.