I want to list out all the file names in the public/images directory for my Scala Play Framework 2 application so that the Play Application just lists those file names to the HTML page. How can this be done?
Is there a right way to access the public/images directory to read files or list the directory? I don't want to use absolute directory paths.
There is method getFile(relateivePath: String): File
on Play
object and also in the Application
class which returns file relative to application root directory. In your case:
Play.getFile("public/images")
return File
object, which represent public/images/
directory. You can call list
or listFiles
on it to get contents of the directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With