I am looking for a maybe better solution to get the path of a file inside a folder. For example:
I have the absolute path: "/storage/emulated/0/Mobile Pauker /Lessons/Berge/Hoechste-Berge.pau.gz"
And I want to get: "Lessons/Berge/Hoechste-Berge.pau.gz"
My current solution is:
filepath.substring(filepath.indexOf("Mobile Pauker ") 15)
But I don't think that this is a good solution.
CodePudding user response:
Please try this val path = File(Environment.getExternalStorageDirectory().toString() File.separator "Lessons/Berge/Hoechste-Berge.pau.gz")
CodePudding user response:
I think I found a good solution:
filepath.split("${Environment.getExternalStorageDirectory()}${Constants.DEFAULT_APP_FILE_DIRECTORY}")[1]
I give the .split() method the path of my "root folder" and take the second part.