github.com/haraldrudell/parl@v0.4.176/pfs/compare-dir-entry.go (about) 1 /* 2 © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pfs 7 8 import "io/fs" 9 10 // compareDirEntry sorts [fs.DirEntry] by basename 11 // - ascending 8-bit character 12 // - used with [slices.SortFunc] and [os.File.ReadDir] 13 func compareDirEntry(a, b fs.DirEntry) (result int) { 14 var an = a.Name() 15 var bn = b.Name() 16 if an < bn { 17 return -1 18 } else if an > bn { 19 return 1 20 } 21 return 22 }