Windows file_find_next() limit of 1000 files?

B

BerickCook

Guest
It seems that there is limit of 1000 files that the file_find functions will search for before giving up.

For example, if you run this code:
Code:
for (Create=0;Create<=2500;Create+=1)
{
    file=file_text_open_write(working_directory+string(Create)+".txt");
    file_text_close(file);
}

Find=file_find_first(working_directory+"*.txt",0);

while (Find!="")
{
    Show=Find;
    Find=file_find_next();
}

show_message(Show);
It should pop up a message that shows "2500.txt". But instead it shows "999.txt".

Is this a bug or an undocumented limitation of the function?
 
A

Aura

Guest
I tested the code you used myself and the function works as expected. It should show 999.txt because it is the last number on the sorting list. 2500 text files are created but numbers larger than 999 (e.g. 1000, 1250, 2500, 1649) are put earlier in the sorting list, so they are filtered by file_find_next() but 999 is the last file to be shown. Files are being sorted depending on the digits used. For instance:

Code:
12
1350
263
2940
37
3843
<...>
999
You can find that out yourself by putting a show_debug_message() call inside the while statement.

Code:
while (find != "") {
   find = file_find_next();
   show_debug_message(find);
}
As you'd notice in the debug messages, files with names larger than 999 have been filtered. But they have been filtered before 999. 999.txt is simply the last file to be filtered, there's no bug or hidden limit.
 
B

BerickCook

Guest
Ah, that makes sense. I didn't think to test for a different internal sorting method! Thanks!
 

Yal

šŸ§ *penguin noises*
GMC Elder
Ah, the common mistake of mixing up string sorting and number sorting~
Fun fact: Windows 8 and onwards actually sorts filenames starting with a number in proper ascending order, Windows 7 and below doesn't. It's so big of a deal (because generic people don't realize the difference between a number and a string) they had to implement it. GM probably uses its own functionality for the search, only sorting alphabetically by strings. The manual doesn't even state in what order you get the 'next' file, so I guess you could see them being sorted in any way a bonus? :p

Anyway, let's just say you're definitely not the first one to be fooled by this effect, don't worry.
 
Top