Skip to content

Instantly share code, notes, and snippets.

@ysb33r
ysb33r / RelativePath.groovy
Last active November 4, 2022 14:18
The Groovy way to obtain a relative path given two paths.
def root= new File('/usr/share')
def full= new File('/usr/share/docs/rpm-4.4')
// Print the relative path of 'full' in relation to 'root'
// Notice that the full path is passed as a parameter to the root.
def relPath= new File( root.toURI().relativize( full.toURI() ).toString() )