H.R. H.R. - 1 year ago 103
Dart Question

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

When I walk a directory using the

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?

Answer Source

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));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download