Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string of folder path

If I have a file path such as:

var/www/parent/folder

How would I go about removing the last folder to return:

var/www/parent

The folders could have any names, I'm quite happy using regex.

Thanks in advance.

like image 215
P Clegg Avatar asked Dec 16 '14 16:12

P Clegg


1 Answers

This is no specialized version of split per se, but you can split by the path.sep like so:

import path from 'path';

filePath.split(path.sep);

like image 137
Mateja Petrovic Avatar answered Oct 20 '22 20:10

Mateja Petrovic