开发者

Find the Latest file version in a folder using Python

开发者 https://www.devze.com 2023-03-14 18:50 出处:网络
Ive been trying to get pyth开发者_如何学Pythonon to try to search all my shotsimport glob latest = sorted(glob.glob(\'dd19_15_00_an[0-9]+\\.avi\'))[-1]

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.


  1. Build a tree representation of your files, recursively
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消