var m = make(map[string][]string)
for _, file := range dir {
if !file.IsDir() {
fileName := file.Name()
ext := filepath.Ext(fileName)
m[ext] = append(m[ext], fileName)
}
}
for ext := range m { sort.Strings(m[ext]) }
Thanks for the replies! filepath.Ext()! Didn't occur to me to try that. It goes to show that the standard library really is pretty complete.
Dirk, I like the for ext := range m { sort.Strings(m[ext]) } solution then I wouldn't need to have a separate sort in each "print" function, it's much clearer that way.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This would make the example even shorter:
@detunized @dirkolbrich
Thanks for the replies!
filepath.Ext()
! Didn't occur to me to try that. It goes to show that the standard library really is pretty complete.Dirk, I like the
for ext := range m { sort.Strings(m[ext]) }
solution then I wouldn't need to have a separate sort in each "print" function, it's much clearer that way.