Does readdir() guarantee an order?

前端 未结 7 1409
时光取名叫无心
时光取名叫无心 2020-11-27 18:50

I\'m getting a list of files on a linux-like system using opendir/readdir. It appears that the directory entries are returned in alphabetical order of file name. However, I

相关标签:
7条回答
  • 2020-11-27 19:35

    It's explicitly not guaranteed. The ordering often follows some rules, but the rules are complicated enough that you should not rely on them. The ordering may, for example, be affected by other operations happening in the same directory, and you can't control those. Treat the ordering as random, and sort things yourself if you need to.

    0 讨论(0)
提交回复
热议问题