3

Path name is : /storage/emulated/0/Xender/video/MyVideo.mp4

I am able to get last file name [MyVideo.mp4] from path using

String path="/storage/emulated/0/Xender/video/MyVideo.mp4";
String filename=path.substring(path.lastIndexOf("/")+1);

https://stackoverflow.com/a/26570321/5035015

Now i want to extract path [/storage/emulated/0/Xender/video] from this path.

I have one use of this path in my code so that i want to do this like this.

How can i do this?

Any help will be appreciated.

Community
  • 1
  • 1
Kishor Ramani
  • 607
  • 1
  • 6
  • 12

1 Answers1

10

new File(path).getParentFile().getName() should work.

With regards to your current code, don't implement your own path parser. Use File.

Also note that this has nothing to do with Android specifically; this is a general Java question.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491