Fix an 'out of range' error when listing files with funny characters