I am trying to list all the files in an assets subdirectory (including sub-subdirectories) but when it comes to identify if a file is a regular file or directory I got stuck.
The directory tree can look like this:
assets/imports
assets/imports/set_one/...(multiple files)
assets/imports/set_two/...(multiple files)
assets/imports/...(other optional files and directories)
What I've tried so far is here:
val IMPORTS_PATH = "imports"
val assetFileNames = context.assets.list(path)!!.asList()
for(file in assetFileNames) {
val subPathString = "$IMPORTS_PATH/$file"
val isDir1 = File(subPathString).isDirectory //always false,
val isFile1 = File(subPathString).isFile //always false, same as above
val subPathObj = Paths.get(subPathString)
val isDir2 = Files.isDirectory(subPathObj) //always false, same as above
I've even tried to read file attributes but got NoSuchFileException although the file does exist.
Is there a clean way to tel if a file is a directory or just regular file?