As for listing the items in a directory... did you even try to look at the manual?
As for limiting the results and putting them in pages,
there are 490 questions in this forum about how to do that for database results, and if you look at the basics behind the answers, you myst be able to use the same idea for your script.