-
-
Notifications
You must be signed in to change notification settings - Fork 12
splitPath
xiao edited this page Jun 15, 2020
·
13 revisions
a function to split a path to its parent and name that recognizes rootdirs(including local and network paths).
if a path passed in is a rootdir the parent part will be empty, and the name is just the path itself.
rootdirs always contain a trailing backslash, such as C:\ or \\mycomputer\sharedfolder\.
note: this function is only suitable for windows full paths. since its main target is to work with root paths.
var result = fswin.splitPath(fullPath);-
fullPathis a string that specifies the path to split - the return value is an object that contains 2 properties:
PARENTandNAME
var fswin = require('fswin');
var paths = ['C:\\PROGRA~1', 'C:\\program files\\Common Files', '\\\\mycomputer\\sharefolder\\somedir\\anotherdir', 'c:\\', '\\\\mycomputer\\sharefolder\\somedir', '\\\\mycomputer\\sharedfolder\\'];
var i, splittedpath;
for (i = 0; i < paths.length; i++) {
splittedpath = fswin.splitPath(paths[i]);
console.log(paths[i] + '" is splitted to "' + splittedpath.PARENT + '" and "' + splittedpath.NAME + '"');
}