-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
  • 58,546
  • 53
  • 279
  • 406

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
  • 82,599
  • 19
  • 151
  • 169
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
  • 836
  • 11
  • 26
0
var url = "file:///data/user/0/com.sleep.app/files/sleep-videos/video2.mp4";

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