iterate over files in directory

Hi all,

How to loop through folder and get file names based on object model?

def read_path_filename(request):

    rec_list = DemoMCall.objects.all()

    folder = settings.STATIC_ROOT

    for filename in os.listdir(folder):
        f = os.fsdecode(filename)

        for id_record , id_agent in rec_list:

            if f.endswith('rec_{0}{1}'.format( id_record.rid , id_agent.info_agent )):
                data = file_path = os.path.join(folder, f )
                return render(request, 'qualityManagement/audio.html' , {'data': data})

# make a template tag

    return render(request, 'qualityManagement/audio.html', {
        'file_path' : file_path })

See the docs at: