path.relative(from, to)
Solve the relative path from from
to to
.
At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve
, which means we see that:
1 | path.resolve(from, path.relative(from, to)) == path.resolve(to) |
Examples:
1 2 3 4 5 | path.relative( 'C:\\orandea\\test\\aaa' , 'C:\\orandea\\impl\\bbb' ) // returns '..\\..\\impl\\bbb' path.relative( '/data/orandea/test/aaa' , '/data/orandea/impl/bbb' ) // returns '../../impl/bbb' |
Note: If the arguments to relative
have zero-length strings then the current working directory will be used instead of the zero-length strings. If both the paths are the same then a zero-length string will be returned.
Please login to continue.