james04
james04

Reputation: 1920

Get all subfolders of a file path android kotlin

Lets say that i have a file path like the following

data/com.myapp.testapp/direcotry_1/directory_2/directory_3/image.jpg

Is there any extension function that can print me the following?

direcotry_1
direcotry_2
direcotry_3

meaning all the subfolders that the filepath contains?

Upvotes: 0

Views: 595

Answers (1)

Bruno
Bruno

Reputation: 4007

You can use the String methods to split your path

String path = "data/com.myapp.testapp/direcotry_1/directory_2/directory_3/image.jpg";
String[] splitted = path.split("/");

Then, you can browse the resulted array.

Note: you can remove the first part, ie "data/package_name", with the use of indexOf() or subString()

Upvotes: 1

Related Questions