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?
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
file is a registered URI scheme (for "Host-specific file names"). So yes, file URIs are URLs.
A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a folder.
What Does Absolute Path Mean? An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders.
Using path module of node.js:
path.dirname('/this/is/a/path/to/a/file');
returns
'/this/is/a/path/to/a'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With