-1

I need to separate the file path from the file name: (some codes did not work in the past) If the path is www.example.com/hi/test/home.html How would I get just www.example.com/hi/test/?

1 Answers1

4

You can use substring and lastIndexOf:

a = "www.example.com/hi/test/home.html";
b = a.substr(0, a.lastIndexOf('/'));

// b = www.example.com/hi/test
Mamdouh Saeed
  • 2,302
  • 1
  • 9
  • 11
Jayce444
  • 8,725
  • 3
  • 27
  • 43