How to Join Folder and File Names into a Path with Join-Path in PowerShell
Join-Path puts folder and file names together into one path, with the right separator between them, so you never type a slash yourself. This guide joins two names, then three, builds a path from your home folder, and shows what joining with + gets wrong, with real output from PowerShell 7.6.10.
The Join-Path page: "The Join-Path cmdlet combines a path and child-path into a single path. The provider supplies the path delimiters."
Syntax
Join-Path <Path> <ChildPath> [<AdditionalChildPath> ...]
Join-Path -Path <Path> -ChildPath <ChildPath>
| Part | What it means |
|---|---|
<Path> | The first part of the path, often a folder, such as notes or $HOME |
<ChildPath> | The part to add after it, such as a file name |
[<AdditionalChildPath> ...] | Optional: more parts, each added after the one before |
-Path, -ChildPath | The same values with their parameter names written out |
Join-Path only builds the text of a path. The Join-Path page: "This cmdlet returns a string that contains the resulting path."
The Example
The example builds paths to a to-do list: a todo.txt file in a notes folder. The folder and the file don't have to exist for this. The commands run in the PowerShell 7.6.10 console on a Mac, in a folder named join-path-demo.
Prerequisites
- PowerShell 7. This guide uses PowerShell 7.6.10:
$PSVersionTable.PSVersion.ToString()printed7.6.10.
Step 1: Join a Folder Name and a File Name
Join-Path 'notes' 'todo.txt'
Join-Path -Path 'notes' -ChildPath 'todo.txt'

notes/todo.txt
notes/todo.txt
Both lines printed the same path: Join-Path put a / between the folder and the file. The first line gives the values by position, the folder first; the second names each one, which reads more clearly in a script.
Step 2: Join More Than Two Names
Join-Path 'notes' '2026' 'todo.txt'
notes/2026/todo.txt
Every name after the second went to the AdditionalChildPath parameter. The Join-Path page: "The AdditionalChildPath parameter allows the joining of an unlimited number of paths."
Step 3: Start the Path at Your Home Folder
$HOME holds your home folder. The about_Automatic_Variables page: "Contains the full path of the user's home directory." So Join-Path can build a path inside it:
Join-Path $HOME 'notes.txt'
/Users/you/notes.txt

Your own user name appears where this shows you. Because the result is a string, you can save it in a variable and use it in later commands:
$file = Join-Path $HOME 'notes.txt'
$file
/Users/you/notes.txt
Step 4: Let Join-Path Handle Extra Slashes
Names that already end or start with a separator don't get a double one:
Join-Path 'notes/' '/todo.txt'
notes/todo.txt
The Join-Path page says the same of its own example: "Existing directory separators \ are handled so there is only one separator between Path and ChildPath."
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Joining with +: 'notes' + 'todo.txt' | notestodo.txt: + joins the text with nothing between | Use Join-Path, which adds the separator |
A name with a space and no quotes: Join-Path notes my todo.txt | notes/my/todo.txt: my and todo.txt became two separate parts | Quote the name: Join-Path notes 'my todo.txt' printed notes/my todo.txt |
Taking the printed path as proof that the file exists: Join-Path 'notes' 'missing.txt' | It printed notes/missing.txt, though there's no such file | Add -Resolve when the path must exist, as the FAQ shows |
FAQ
Does Join-Path check that the file exists?
Not by default. Add -Resolve and it looks the path up: Join-Path 'notes' 'missing.txt' -Resolve failed with Join-Path: Cannot find path '/Users/you/join-path-demo/notes/missing.txt' because it does not exist.
Which separator does Join-Path use?
The one the provider gives it. The Join-Path page: "The provider supplies the path delimiters." On this Mac's file system, that was /. The page's own examples show \, as in path\childpath.
Conclusion
Join-Path 'notes' 'todo.txt' printed notes/todo.txt: Join-Path chose the separator, so you don't type one. Add more names for deeper paths, quote names that have spaces, and add -Resolve when the path must exist.
Additional Resources
- Join-Path — the parameters, including
AdditionalChildPathandResolve, with examples. - about_Automatic_Variables —
$HOMEand the other variables PowerShell sets for you.
