# Class RelativePath

java.lang.Object
org.gradle.api.file.RelativePath

All Implemented Interfaces:
  `Serializable, CharSequence, Comparable<RelativePath>`

public class RelativePath extends Object implements Serializable, Comparable<RelativePath>, CharSequence

Represents a relative path from some base directory to a file. Used in file copying to represent both a source and target file path when copying files.

`RelativePath` instances are immutable.

Since:
  0.8
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final RelativePath`
  `EMPTY_ROOT`
  Relative path.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RelativePath(boolean endsWithFile, String... segments)`
  Creates a `RelativePath`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `RelativePath`
  `append(boolean endsWithFile, String... segments)`
  Appends the given names to the end of this path.
  `RelativePath`
  `append(RelativePath other)`
  Appends the given path to the end of this path.
  `char`
  `charAt(int index)`
  `int`
  `compareTo(RelativePath o)`
  `boolean`
  `equals(Object o)`
  `File`
  `getFile(File baseDir)`
  Returns the file.
  `String`
  `getLastName()`
  Returns the last name.
  `@Nullable RelativePath`
  `getParent()`
  Returns the parent of this path.
  `String`
  `getPathString()`
  Returns the path string.
  `String[]`
  `getSegments()`
  Returns the segments.
  `int`
  `hashCode()`
  `boolean`
  `isFile()`
  Returns whether file is set.
  `int`
  `length()`
  `static RelativePath`
  `parse(boolean isFile, String path)`
  Parse.
  `static RelativePath`
  `parse(boolean isFile, @Nullable RelativePath parent, String path)`
  Parse.
  `RelativePath`
  `plus(RelativePath other)`
  Appends the given path to the end of this path.
  `RelativePath`
  `prepend(String... segments)`
  Prepends the given names to the start of this path.
  `RelativePath`
  `replaceLastName(String name)`
  Returns a copy of this path, with the last name replaced with the given name.
  `ListIterator<String>`
  `segmentIterator()`
  Segment iterator.
  `CharSequence`
  `subSequence(int start, int end)`
  `String`
  `toString()`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface CharSequence

  `chars, codePoints, getChars, isEmpty`

- ## Field Details

  - ### EMPTY_ROOT

    public static final RelativePath EMPTY_ROOT
    Relative path.
    Since:
      3.2

- ## Constructor Details

  - ### RelativePath

    public RelativePath(boolean endsWithFile, String... segments)
    Creates a `RelativePath`.
    Parameters:
      `endsWithFile` - - if true, the path ends with a file, otherwise a directory
    Since:
      0.8

- ## Method Details

  - ### getSegments

    public String[] getSegments()
    Returns the segments.
    Since:
      0.8

  - ### segmentIterator

    public ListIterator<String> segmentIterator()
    Segment iterator.
    Since:
      0.8

  - ### isFile

    public boolean isFile()
    Returns whether file is set.
    Since:
      0.8

  - ### getPathString

    public String getPathString()
    Returns the path string.
    Since:
      0.8

  - ### length

    public int length()
    Specified by:
      `length` in interface `CharSequence`

  - ### charAt

    public char charAt(int index)
    Specified by:
      `charAt` in interface `CharSequence`

  - ### subSequence

    public CharSequence subSequence(int start, int end)
    Specified by:
      `subSequence` in interface `CharSequence`

  - ### getFile

    public File getFile(File baseDir)
    Returns the file.
    Since:
      0.8

  - ### getLastName

    public String getLastName()
    Returns the last name.
    Since:
      0.8

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Specified by:
      `toString` in interface `CharSequence`
    Overrides:
      `toString` in class `Object`

  - ### getParent

    public @Nullable RelativePath getParent()
    Returns the parent of this path.
    Returns:
      The parent of this path, or null if this is the root path.
    Since:
      0.8

  - ### parse

    public static RelativePath parse(boolean isFile, String path)
    Parse.
    Since:
      0.9

  - ### parse

    public static RelativePath parse(boolean isFile, @Nullable RelativePath parent, String path)
    Parse.
    Since:
      0.9

  - ### replaceLastName

    public RelativePath replaceLastName(String name)

    Returns a copy of this path, with the last name replaced with the given name.

    Parameters:
      `name` - The name.
    Returns:
      The path.
    Since:
      0.9

  - ### append

    public RelativePath append(RelativePath other)

    Appends the given path to the end of this path.

    Parameters:
      `other` - The path to append
    Returns:
      The new path
    Since:
      0.9

  - ### plus

    public RelativePath plus(RelativePath other)

    Appends the given path to the end of this path.

    Parameters:
      `other` - The path to append
    Returns:
      The new path
    Since:
      0.9

  - ### append

    public RelativePath append(boolean endsWithFile, String... segments)
    Appends the given names to the end of this path.
    Parameters:
      `endsWithFile` - when true, the new path refers to a file.
      `segments` - The names to append.
    Returns:
      The new path.
    Since:
      0.9

  - ### prepend

    public RelativePath prepend(String... segments)
    Prepends the given names to the start of this path.
    Parameters:
      `segments` - The names to prepend
    Returns:
      The new path.
    Since:
      0.9

  - ### compareTo

    public int compareTo(RelativePath o)
    Specified by:
      `compareTo` in interface `Comparable<RelativePath>`