Search code examples
dartdart-io

Why does dart's listSync() behave differently on Windows and Ubuntu?


When I walk a directory using the listSync function in Windows the entries are sorted but when I run the same code in Ubuntu they are not:

enter image description here

Why is that?


Solution

  • This (likely) is due to the (non)-Guarantee of the Windows FS.

    From another post:

    On a FAT filesystem, the entries in any given directory are unsorted, causing the tree-walk to be unsorted. NTFS directories, by contrast, are always sorted

    You could always sort your output though:

    var files = directory.listSync()..sort((a, b) => a.path.compareTo(b.path));