# file

fun file(path: Any): File(source)

Resolves a file path relative to this script's target base directory.

If this script targets org.gradle.api.Project, then `path` is resolved relative to the project directory.

If this script targets org.gradle.api.initialization.Settings, then `path` is resolved relative to the build root directory.

This method converts the supplied path based on its type:

- A CharSequence, including String. A string that starts with `file:` is treated as a file URL.

- A File. If the file is an absolute file, it is returned as is. Otherwise it is resolved.

- A java.nio.file.Path. The path must be associated with the default provider and is treated the same way as an instance of `File`.

- A URI or java.net.URL. The URL's path is interpreted as the file path. Only `file:` URLs are supported.

- A org.gradle.api.file.Directory or org.gradle.api.file.RegularFile.

- A org.gradle.api.provider.Provider of any supported type. The provider's value is resolved recursively.

- A java.util.concurrent.Callable that returns any supported type. The callable's return value is resolved recursively.

#### Return

The resolved file.

#### Parameters

path

The object to resolve as a `File`.

fun file(path: Any, validation: PathValidation): File(source)

Resolves a file path relative to this script's target base directory.

#### Return

The resolved file.

#### Parameters

path

The object to resolve as a `File`.

validation

The validation to perform on the file.

#### See also

file