readdir() does not guarantee any other order above that which is OS disk read order.
According to test which i made on few platforms - Solaris - sun4sol, x86 sol, linux, Windows with the sample code all results were displated in a random manner.
source: readdir() beginning with dots instead of files
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
int main() {
DIR *dir;
struct dirent *dp;
char * file_name;
char dirpath [100] ;
while(1==1){
printf("Choose dir:");
scanf("%s",dirpath);
dir = opendir(dirpath);
while ((dp=readdir(dir)) != NULL) {
if ( !strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") )
{
// do nothing (straight logic)
} else {
file_name = dp->d_name; // use it
printf("file_name: \"%s\"\n",file_name);
}
}
closedir(dir);
}
return 0;
}
unzip
ortar
extracting them as such...readdir
provides no order. – Frymirescandir
may be useful if you want to order the results or have random access to them. It's standardized in POSIX 2008 and was a common extension before then. – Frymire