Resolve full and relative file paths in PowerShell

  • Published: 2026.11.18
  • Updated: 2026.11.18
  • Windows

A relative path can point to a different place when you run a command from another folder. Before passing a filename to a script, checking its full path can help you spot a working-directory mistake without changing the file.

Resolve-Path resolves paths that already exist. The examples below use Windows PowerShell 5.1 and PowerShell 7 to inspect a file’s full path, expand a wildcard pattern, and return a path relative to the current location.

Inspect an existing file’s full path

Suppose the current folder contains a data directory with a file named report[1].txt. Replace the example with the file you want to inspect.

Resolve-Path -LiteralPath '.\data\report[1].txt' | Select-Object Path, Provider

The Path column shows the resolved full path. Here, .\ means that the path starts from PowerShell’s current location. If the result names an unexpected folder, compare that location with the directory where you saved the file.

-LiteralPath treats the supplied name literally instead of interpreting characters such as square brackets as wildcards. It is useful for filenames like report[1].txt.

Provider identifies the PowerShell provider handling the path. The local-file example used FileSystem. PowerShell can also resolve paths handled by other providers, so check what kind of location you are inspecting before treating every result as an ordinary file.

Expand a wildcard pattern into matching paths

Use -Path when you want the wildcard to select several matching items.

Resolve-Path -Path '.\data\*.txt' | Select-Object Path

With report[1].txt and notes.txt in the sample directory, this returned two paths. A pattern can return several results. If the next operation expects just one file, inspect the candidates before choosing which path to pass to it.

Return a path relative to the current location

Add -Relative when a path based on the current folder is more useful than a full path.

Resolve-Path -LiteralPath '.\data\report[1].txt' -Relative

The result in this example was .\data\report[1].txt. With -Relative, the output is a string rather than the usual object with Path and Provider properties. Keep the working location in mind when saving or reusing a relative path: it can refer to a different file from another folder.

Use a different check for a path that does not exist

Resolving .\data\missing.txt in the sample directory produced an error because the file did not exist. Resolving a path does not create the file, and it is different from constructing the name of a file you plan to save later.

To combine a directory with a planned filename, see building paths with Join-Path. To ask whether a file or folder exists and receive a Boolean result, see checking file and folder paths with Test-Path.

If resolution fails, check the filename, current location, and whether the target is accessible. The error alone does not establish that the file was deleted or damaged.

Reference

Microsoft Learn: Resolve-Path