Jack Richard Jack Richard - 1 year ago 137
Javascript Question

JavaScript-How To Separate Path from File Name

I need to separate the file path from the file name:
If the path is www.example.com/hi/test/home.html
How would I get just www.example.com/hi/test/?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download