# pathtoroot

    .pathtoroot granularity:{RootGranularity = RootGranularity.PROJECT} -> String

Content copied to clipboard

Retrieves the relative path to the root of the file system. The root of the file system is determined by the working directory of either the project or the current subdocument, depending on the specified granularity.

If set to RootGranularity.PROJECT, the root is the parent directory of the target file being processed by the `quarkdown compile` command. If set to RootGranularity.SUBDOCUMENT, the root is the parent directory of the current subdocument file.

For example, consider the following file tree:

    My-Project/
    ├─ main.qd
    ├─ file.txt
    ├─ subdocuments/
       ├─ subdocument.qd
       ├─ file.txt
    ├─ utils/
       ├─ example.qd

Content copied to clipboard

If `main.qd` invokes `.pathtoroot`, the result is `.` regardless of the granularity, since the working directory is the root of the project.

Consider the content of `example.qd`:

    .read {.pathtoroot/file.txt}

    .read {.pathtoroot granularity:{subdocument}/file.txt}

Content copied to clipboard

Now, assume `main.qd` invokes `.include {utils/example.qd}`. Regardless of the granularity, the `.pathtoroot` calls in `example.qd` return `..`, so that `My-Project/file.txt` is correctly accessed by `My-Project/utils/example.qd` through the relative path `../file.txt`.

Assume now that `subdocument.qd` is a subdocument and invokes `.include {../utils/example.qd}`.

- With RootGranularity.PROJECT, the `.pathtoroot` calls in `example.qd` return `..`, so that `My-Project/file.txt` is accessed by `My-Project/utils/example.qd` through the relative path `../file.txt`.

- With RootGranularity.SUBDOCUMENT, the `.pathtoroot` calls in `example.qd` return `../subdocuments`, so that `My-Project/subdocuments/file.txt` is accessed by `My-Project/utils/example.qd` through the relative path `../subdocuments/file.txt`.

#### Return

a string value of the relative path to the root of the file system

#### Parameters

granularity

- Optional
- Likely named

the granularity for determining the root of the file system

#### Values

- `project`
- `subdocument`

#### Throws

IllegalStateException

if the relative path cannot be determined