如何列出Play Framework 2 Scala应用程序中public/images目录中的所有文件? [英] How to list out all the files in the public/images directory in a Play Framework 2 Scala application?
问题描述
我想列出我的Scala Play Framework 2应用程序public/images目录中的所有文件名,以便Play应用程序仅将这些文件名列出到HTML页面.该怎么办?
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?
是否存在访问public/images目录以读取文件或列出目录的正确方法?我不想使用绝对目录路径.
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.
推荐答案
在 Application
类,该类返回相对于应用程序根目录的文件.就您而言:
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")
返回 File
对象,代表public/images/
目录.您可以调用list
或listFiles
来获取目录的内容.
return File
object, which represent public/images/
directory. You can call list
or listFiles
on it to get contents of the directory.
这篇关于如何列出Play Framework 2 Scala应用程序中public/images目录中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!