1] Which of the functions is faster?
2] what are the differences?
Differences
1] readdir returns the name of the next entry in the directory. Scandir returns an array of files and directories from the directory.
2] readdir has to have a resource handle open until all the entries are read. scandir, perhaps creates an array of all the entries and closes the resouce handle?
Just getting the results (without doing anything), readdir is a minimum faster:
Gives:
Then of course it depends on what you intend to do. If you have to write another loop with scandir(), it will be slower.