How to list out all the files in the public/images directory in a Play Framework 2 Scala application? - scala

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.

Related

retrieve all files in subfolders in sharepoint document library using REST

I have a folder in a document library and that contains subfolders and each subfolder contains files.
I want to retrieve all the files in these subfolders using REST. I know how to get the files in each folder but is there any way to get all these files in one REST call... Any help?
You could use the below endpoint to retrieve all files in a library:
/_api/web/lists/getbytitle('Documents')/items?$expand=File&$select=File&$filter=FSObjType eq 0

Scala: Create File with a Folder Using Relative Path (Not Absolute Path)

In my Scala code I want to create a folder "c:/temp" and then create a file "file.txt" within that folder. I don't want to have to use "c:/temp/file.txt". So, I want to use the relative path of the file to create it within that folder.
Imagine how a human creates a folder and then a file? He creates a folder; goes in the folder, and then creates the file inside that folder. That's what I want to do.
=====
Added the following to make this more clear:
Let's say I created the folder and I have a File object called myFolder that represents that folder. What I want is to be able to do something like myFolder.createFile("file.txt").
val subFile = new File(myFolder, "file.txt")
From the description of the File(File parent, String child) constructor found at the docs page:
Creates a new File instance from a parent abstract pathname and a child pathname string.

Get list of files from a folder inside a packaged project

I have a list of public assets inside the "src/main/resources" folder that looks like this:
public/images/
asd1.png
asd2.png
I'm trying to list all the files inside the "public/images/" directory, as it is a compiled project using sbt universal:packageBin I'm trying to access the assets using:
val input = getClass.getResourceAsStream("/public/images/")
or
val input = getClass.getResource("/public/images/")
getResourceAsStream returns an empty result and getResource returns a URL object that contains a direct path to the folder but I cannot list anything inside that folder even with new File(getClass.getResource("/public/images/")) as the check for .isDirectory() returns a false as a response or .listFiles() throws an exception.
What is the best way to achieve this?

How can I rename file uploaded to s3 using javascript api?

'pickAndStore' method allows me to specify full path to the file, but I don't know it's extension at this point (file path has to be defined before file is uploaded, so it's not possible to provide a path with correct extension).
if I use 'pick' and then 'store' I have 2 files (because both methods uploads file to the s3). I can delete 'old' file, but it's not optimal and can be pain (take ages) with really big files.
Is there any better solution? Ideally to rename existing file.
Currently, there is no workaround for renaming file.
However, in our Javascript API v2 we are planing to add new callback function. onStart callback will be fired after user pick file but before file uploading. There could be option like renaming file based on original filename.
We will keep you updated.

Are there any easy Read/write to file system from Metro Apps when the files are in nested folders

I'm working on a application that downloads some files to the local storage for caching. The files online are sometimes in 3 or 4 nested folders and I would like to also keep this hierarchy in my cache folder.
Is there no easy way other then having to (await (await folder.GetFolderAsync("dir1")).GetFolderAsync("dir2)) and so on? Now it's hardcoded with dir1 and dir2.
What's the easiest way when the file path is a string like "MyFolder/OtherFolder/lastFolder/file.xml"?
The static member function StorageFolder::GetFolderFromPathAsync can be used to get a StorageFolder object for a folder given its path.