I'm trying to execute a directory list and make a search by filename in a TinyDb database, like below:
from tinydb import TinyDB, Query
import os, fnmatch
db = TinyDB('DB_links_filenames.json')
User = Query()
def getFieldData(campo,nome):
results = db.search(User.file == nome )
result = [r[campo] for r in results]
return result
listOfFiles = os.listdir('/home/files')
pattern = "*.mp4"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
print(getFieldData('url',entry))
The problem is the filename goes to the function as expected, but appears to be blank in db.search...
, I've tried several methods like:%nome or [nome] or (nome)
in order to add the variable to search query but no sucess, the result is always the same []
.
If the name of file is inserted direct to the query db.search(User.file == 'filename' )
everything works normally.
Any suggestion what could be?