Node.js path.toNamespacedPath() Method
The path.toNamespacedPath() method is used to find the equivalent namespace-prefixed path from the given path. This method is meaningful only on Windows Systems. It would return the same path without modification on POSIX systems. If the path is not a string, it would be returned without modification.
Syntax:
path.toNamespacedPath( path )
Parameters: This function accepts single parameter as mentioned above and described below:
- path: It is an string which contains the path that has to be converted.
Return Value: It returns a string with an equivalent namespace-prefixed path.
Below programs illustrate the path.toNamespacedPath() method:
Example 1:
// Import the path module const path = require( 'path' ); let originalPath = "C:\\Windows\\users" ; console.log( "Original Path:" , originalPath); let nameSpacedPath = path.toNamespacedPath(originalPath); console.log( "Namespaced Path:" , nameSpacedPath); |
Output:
Original Path: C:\Windows\users Namespaced Path: \\?\C:\Windows\users
Example 2:
// Import the path module const path = require( 'path' ); let originalPath = "C:\\Windows\\users\\..\\admin" ; console.log( "Original Path:" , originalPath); let nameSpacedPath = path.toNamespacedPath(originalPath); console.log( "Namespaced Path:" , nameSpacedPath); |
Output:
Original Path: C:\Windows\users\..\admin Namespaced Path: \\?\C:\Windows\admin
Reference: https://nodejs.org/api/path.html#path_path_tonamespacedpath_path
Contact Us