Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python glob sort numerically

import re 
import math
from pathlib import Path 

file_pattern = re.compile(r'.*?(d+).*?')
def get_order(file):
    match = file_pattern.match(Path(file).name)
    if not match:
        return math.inf
    return int(match.groups()[0])

sorted_files = sorted(files, key=get_order)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #glob #sort #numerically
ADD COMMENT
Topic
Name
7+2 =