How to get correctly PDF file from directory for downloading

Good day! Can you please suggest what is the best way to scan the directories for PDF files and create the download links from them.

—twig
{% for book in pages.find(’/media’).children %}
{% for a in book.media.files() %}
{{ a.items.basename }}
{% endfor %}
{% endfor %}

Almost forgot, how we can print out only the PDF files?

Your code looks like it should work fine. is it not? You should be able to inspect the extension ie:

{% if a.extension == 'pdf' %}
...
{% endif %}
---

Thank you. Just thought there is another way… just for learning… :slight_smile: