Jul-04-2022, 10:21 AM
(Jul-04-2022, 09:56 AM)snippsat Wrote: For sorting pathlib object addkey=str
.
Test.
from pathlib import Path from natsort import natsorted, humansorted from pprint import pprint outputs = Path(r'G:\div_code\answer\sort_test') search = "*.txt" sorted_outputs = humansorted(outputs.glob(search), key=str) pprint(sorted_outputs)
Output:[WindowsPath('G:/div_code/answer/sort_test/file_1.txt'), WindowsPath('G:/div_code/answer/sort_test/file_2.txt'), WindowsPath('G:/div_code/answer/sort_test/file_3.txt'), WindowsPath('G:/div_code/answer/sort_test/file_10.txt'), WindowsPath('G:/div_code/answer/sort_test/file_11.txt'), WindowsPath('G:/div_code/answer/sort_test/file_33.txt')]
Ah thank you. That worked fine.
