Any Way to Reset DirectoryIterator Back to First File?


#1

I have an algorithm that, at this time, requires me to iterate through the directory of files multiple times, is there any way to reset the directory iterator to point back to the first file?


#2

Nope. There’d be little point in the iterator providing a method for that when you can just create a new iterator to start again.

But remember that iterating files is slow, it may be smarter for you to make a list of them first time round and then just iterate your list.


#3

Thanks for the feedback Jules! I was thinking of just putting it all in a loop and letting the iterator go out of scope, then re-declaring the original one again, but making a list sounds like a better idea, one I didn’t consider. I’ll get on this. Thanks!