in reply to Why can't I readdir multiple times in a while loop?

I'm not %100 sure about this, but I suspect that readdir is working like the file read operators. You can't re-read a file from the same handle again until you rewind it. Even if you could, since you're program is trying to "look for new files" you'll probably have to close and re-open the dir handle on each loop. I dont think there is a way to rewind directory handles (you can rewind most filehandles with seek).
  • Comment on Re: Why can't I readdir multiple times in a while loop?

Replies are listed 'Best First'.
RE: Re: Why can't I readdir multiple times in a while loop?
by jlistf (Monk) on Aug 24, 2000 at 22:31 UTC
    well... there is a rewinddir function. though i've never used it and i'm not sure what it does if the directory gets altered.

    jeff

    Update: apparently there's also a seekdir function. i'd suggest looking into these two functions and see if they'll do what you want them to do.
      Unfortunately, using both rewinddir and seekdir didn't help. Instead of getting nothing the second time through the loop, the array was populated with the values of the files that were previously there and now nonexistent. It may have something to do with the fact that I'm running this on a Win32 platform, I dunno.
      I just moved the opendir and closedir inside the loop, and it works fine now. It makes me feel dirty to have code that opens and closes a directory handle roughly once a second, but it works for now.