I am trying to debug right now in C and am curious if it is alright to call opendir() repeatedly without having to first call closedir() because I am trying to run a loop to open sub-directories when the while-loop that calls readdir() encounters them. And I assume that closing the current directory would cause me to lose the ability to read it.
+5
A:
You can use opendir()
repeatedly. Just keep your DIR *
s and call closedir()
when you're done with each.
iWerner
2009-11-16 15:49:30
Alrighty! Thanks :)
Kenji
2009-11-16 15:51:30
+2
A:
Yes, you can do multiple opendir() calls. Be wary of symbolic link loops which could cause you to get into an infinite loop and consume all available memory.
Jim Garrison
2009-11-16 15:51:52
+1
A:
You'll have to be careful not to leak the DIR*
that you are collecting, but as long as you don't hit the file-descriptor limit you shouldn't have any problem with having multiple opendir()
open at the same time.
Douglas Leeder
2009-11-16 15:53:16