add regex to test if audio file names are correctly formated

This commit is contained in:
Tomasz Frątczak 2024-02-17 16:49:12 +01:00
parent 13ae7e5b57
commit 1fe049e065
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import logging
import time
import os
import re
from datetime import datetime
@ -33,11 +34,15 @@ class Picker:
if file_marker < marker:
return file
def match_name(self, input):
pattern = r"^\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}\.m4a$"
return bool(re.match(pattern, input))
def list_files(self):
files = []
for filename in os.listdir(self.directory):
filepath = os.path.join(self.directory, filename)
if os.path.isfile(filepath) and filename.endswith(".m4a"):
if os.path.isfile(filepath) and self.match_name(filename):
files.append(filepath)
return files