-2

I have a file path as shown below.The last part (i.e. video2.mp4) is dynamically changed.I'm using Javascript/Typescript.

file:///data/user/0/com.sleep.app/files/sleep-videos/video2.mp4

Question: How to get the file:///data/user/0/com.sleep.app/files/sleep-videos/ part only from above string.

Sampath
  • 63,341
  • 64
  • 307
  • 441

3 Answers3

2
var string = 'file:///data/user/0/com.sleep.app/files/sleep-videos/video2.mp4';


var stringPart = string.substring(0,string.lastIndexOf("/")+1);
Tushar
  • 85,780
  • 21
  • 159
  • 179
ajay92x
  • 83
  • 11
0

If only the filename changes try something like here

^(.+)/([^/]+)$

Try it at regexr. Your first group is the dirname, the second group the basename.

If you have further requirements/information (e.g. which tools you use), please refine your question.

BNT
  • 936
  • 10
  • 27
0
var url = "file:///data/user/0/com.sleep.app/files/sleep-videos/video2.mp4";

url= url.split("/");
url.pop();
url = url.join("/");
Mamallan
  • 41
  • 6