Using a function to create a list of files from directory

I want to sort by file name, because right now for some reason all files are in random order and not the order that they are organized (but optimally alphabetically in my case). From what I understand I can use the sort function for this. I do not understand where functions like these should be entered in the code? Or if I am even using it correctly (because I am only getting errors when I try)

Another question I have is if it is possible to change the shortcode so that:

{{ range readDir "static/Folder1" }}

Is somehow “dynamic”? So for example, when using the shortcode, I would instead type

{{< pdf ../the folder I want to access/>}}

Instead of having it set on one specific folder.

Thank you for your help