Find the Latest file version in a folder using Python
Ive been trying to get pyth开发者_如何学Pythonon to try to search all my shots
import glob
latest = sorted(glob.glob('dd19_15_00_an[0-9]+\.avi'))[-1]
Note: a normal sort is OK if your versions have zero padding. If they had no zero padding, you needed some kind of natural sort, which complicated things a bit.
- Build a tree representation of your files, recursively
- Do the search
For "02" suffixes it's quite easy, you use a regex like [0-9]+
. However what happens for other kind of suffixes or prefixes? You could implement something that calculates the levenstein distance only in some given intervals.
精彩评论