Skip to content

Instantly share code, notes, and snippets.

@jaimealves
Created December 20, 2021 16:19
Show Gist options
  • Select an option

  • Save jaimealves/4adfb27345c6b0de099fc36ecc098a48 to your computer and use it in GitHub Desktop.

Select an option

Save jaimealves/4adfb27345c6b0de099fc36ecc098a48 to your computer and use it in GitHub Desktop.
Sorted glob
# armazenar o nome dos arquivos
glob_results = glob.glob('*.txt')
# para se obter resultado do glob em ordem alfabetica dos nomes dos arquivos
print(sorted(glob_results))
# para se obter resultado do glob em ordem de tamanho dos arquivos
print(sorted(glob_results, key=os.path.getsize))
# fonte: https://www.kite.com/python/answers/how-to-sort-the-results-of-the-glob-function-in-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment