mardi 7 avril 2015

Get directory from a file path or url

I am trying to get the directory location of a file, and I'm not sure how to get it. I can't seem to find a module that allows me to do this.


So for example say I have this string:



/this/is/a/path/to/a/file.html


how can I get this:



/this/is/a/path/to/a


I know I can use something like this:



path.substr(0, path.lastIndexOf("/") - 1);


But I am not sure if that is as good of a method as something that might be built in to node.


I have also tried:



var info = url.parse(full_path);
console.log(info);


and the result doesn't return what I am looking for, that gets the full path including the filename.


So, is there something built into node that can do this and do it well?


Aucun commentaire:

Enregistrer un commentaire