How to Copy a File Path That Works in the Terminal
In File Explorer, select the file and press Ctrl+Shift+C (Windows 11), or hold Shift, right-click and choose Copy as path. You get the full path in double quotes, such as "C:\Users\Sam\My Project\app.log". That works as-is in Command Prompt and as a PowerShell argument. For Git Bash and WSL, convert it to a Unix-style path, and in code, use a raw string or escape the backslashes.
Quick reference: what each target needs
| Where you paste | What to use | Example |
|---|---|---|
| Command Prompt | The copied path as-is | type "C:\Users\Sam\My Project\app.log" |
| PowerShell (argument) | As-is; single quotes if the path has $ or a backtick | Get-Content 'C:\Users\Sam\$work\app.log' |
| PowerShell (run a program) | & before the quoted path | & "C:\Program Files\Tool\tool.exe" --version |
| Git Bash | Single quotes, or convert with cygpath | cygpath -u 'C:\Users\Sam\My Project' |
| WSL | Convert with wslpath | wslpath 'C:\Users\Sam\My Project' |
| Python | A raw string | r"C:\Users\Sam\My Project\app.log" |
| JSON | Double every backslash | "C:\\Users\\Sam\\app.log" |
How to copy a file path to the clipboard covers every way to get the path in the first place, including the address bar and multiple files.
Command Prompt
Command Prompt treats backslashes as ordinary characters, so the copied path works without changes. Keep the double quotes: without them, a path with a space splits into two arguments.
type "C:\Users\Sam\My Project\app.log"
cd /d "D:\Projects\app"
cd on its own doesn't switch drives; /d makes it change drive and folder together. Command Prompt can't use a network path such as \\server\share as its current folder. Use pushd "\\server\share\folder" instead, which maps a temporary drive letter (starting from Z:) and switches to it; popd removes the mapping.
PowerShell
The copied path also works as a PowerShell argument:
Get-Content "C:\Users\Sam\My Project\app.log"
Backslashes are literal in PowerShell. Its escape character is the backtick (` `), not the backslash, so \t or \n` inside a path is never turned into a tab or a newline. Three things do catch people out:
$in a path. Inside double quotes, PowerShell expands$nameas a variable, so a folder called$worksilently becomes something else. Wrap paths that contain$or a backtick in single quotes, which PowerShell treats literally.- Square brackets.
-Pathtreats[and]as wildcard characters, soC:\Logs\[old]\app.logmay not match. Use-LiteralPathinstead:Get-Content -LiteralPath 'C:\Logs\[old]\app.log'. - Running a program. Pasting a quoted path on its own and pressing Enter just prints the text, because PowerShell sees a string. Put the call operator in front:
& "C:\Program Files\Tool\tool.exe" --version.
The PowerShell clipboard cheat sheet shows how to read a copied path straight from the clipboard with Get-Clipboard.
Git Bash
Bash uses the backslash as its escape character. Unquoted, cd C:\Users\Sam loses every backslash and becomes C:UsersSam. Two reliable fixes:
- Use single quotes. Bash keeps everything inside single quotes literally:
ls -l 'C:\Users\Sam\My Project'. - Convert to a Unix-style path. Git Bash includes
cygpath, which turns a Windows path into the/c/...form Bash tools expect:
cd "$(cygpath -u 'C:\Users\Sam\My Project')"
Inside double quotes, Bash keeps a backslash unless it comes before $, a backtick, ", \ or a newline. That's why the double-quoted path from Copy as path often works, but single quotes remove the guesswork.
WSL
WSL mounts Windows drives under /mnt, so C:\Users\Sam is /mnt/c/Users/Sam. The wslpath tool does the translation:
wslpath 'C:\Users\Sam\My Project\app.log'
# /mnt/c/Users/Sam/My Project/app.log
cd "$(wslpath 'C:\Users\Sam\My Project')"
Use single quotes around the Windows path, for the same reason as in Git Bash. Going the other way, wslpath -w turns a Linux path into a Windows one, and wslpath -m gives a Windows path with forward slashes.
Windows Terminal Preview can also do this when you drag a file onto the window: its pathTranslationStyle profile setting accepts "wsl" (C:\ becomes /mnt/c), "msys2" (/c), "cygwin" and "mingw". The default is "none". WSL clipboard: what crosses into Windows covers copying text the other way.
Python, JavaScript and JSON
Pasting a Windows path into source code fails for a different reason: in most languages a backslash inside a string starts an escape sequence.
Python. "C:\Users\Sam\app.log" is a syntax error, because \U starts a Unicode escape. Put r in front to make a raw string, or use forward slashes:
from pathlib import Path
log = Path(r"C:\Users\Sam\My Project\app.log")
same = Path("C:/Users/Sam/My Project/app.log")
A raw string can't end with a single backslash, so r"C:\Users\Sam\" fails. Leave the trailing backslash off; pathlib doesn't need it.
JavaScript and Node.js. A normal string silently corrupts the path: \n becomes a newline and an unknown escape such as \U just drops the backslash. Use forward slashes, which Node's path module accepts on Windows, or String.raw:
const a = "C:/Users/Sam/My Project/app.log";
const b = String.raw`C:\Users\Sam\My Project\app.log`;
JSON. JSON requires every backslash to be escaped, so C:\Users\Sam\app.log becomes "C:\\Users\\Sam\\app.log". Forward slashes are also valid in a JSON string, and most Windows tools accept them.
Paths that cause trouble everywhere
- Spaces: quote the path in every shell. Unquoted,
C:\Program Files\Tool\tool.exebecomes the commandC:\ProgramwithFiles\Tool\tool.exeas its argument. - Very long paths: many Windows tools still stop at the classic 260-character
MAX_PATHlimit, whatever the quoting. Deep project trees hit this first; how to pin long monorepo paths has ways to work with them. - Wrong format for the shell: a
/mnt/c/...path means nothing to a Windows program, and aC:\...path means nothing to a Linux tool unless it's converted. If a path "doesn't exist", check which side of that line you're on.
FAQ
Why does Copy as path add quotes?
So a path with spaces stays one argument when you paste it into a command. Remove them only when pasting somewhere that isn't a command line, such as a file dialog's name box.
How do you copy the path of the current folder in a terminal?
In PowerShell, (Get-Location).Path | Set-Clipboard. In Command Prompt, cd | clip. In WSL or Git Bash, pwd prints it; why pasting into terminals strips formatting explains what happens to text going the other way.
Can you paste a path into Windows Terminal by dragging the file?
Yes. Dragging a file from Explorer onto Windows Terminal types its path at the cursor. Use pathTranslationStyle in Windows Terminal Preview if you want it converted for WSL or Git Bash automatically.
Related reading
- How to Copy a File Path in Windows 11 (Copy as Path)
- WSL Clipboard: Copy and Paste Between Linux and Windows
- Long File Paths on Windows: Fix MAX_PATH in Git and Monorepos
- PowerShell Clipboard Cheat Sheet: Get-Clipboard and Set-Clipboard
Sources
- Announcing Windows 11 Insider Preview Build 22463 (Windows Insider Blog) — Ctrl+Shift+C copies the selected item's path.
- about_Quoting_Rules (Microsoft Learn) — single quotes are literal; double quotes expand variables and backtick escapes.
- about_Operators (Microsoft Learn) — the call operator
&. - Get-Content (Microsoft Learn) —
-LiteralPathtreats no characters as wildcards. - pushd (Microsoft Learn) — network paths get a temporary drive letter.
- Double Quotes (GNU Bash manual) — when a backslash keeps its special meaning.
- cygpath (Cygwin User's Guide) — converting between Windows and Unix path formats.
- WSL release notes (Microsoft Learn) —
wslpathand its-u,-wand-moptions. - Working across file systems (Microsoft Learn) — Windows drives mounted under
/mnt/c. - Advanced profile settings (Windows Terminal docs) —
pathTranslationStylefor drag-and-drop paths. - Lexical analysis: string literals (Python docs) — escape sequences and raw strings.
- Path module (Node.js docs) — Windows accepts forward and backward slashes.
- RFC 8259 (IETF) — backslashes in JSON strings must be escaped.
- Maximum path length limitation (Microsoft Learn) — the 260-character MAX_PATH limit.
Deepender Yadav created Edge Drop and builds and tests it, from the edge-hover shelf to each release. A B.Tech Computer Science Engineering student, Deepender writes the Edge Drop guides, comparisons and developer posts, and checks product details against the app's source code.
GitHub · LinkedInCopy. Stack. Drop.
Transform your clipboard into an interactive edge shelf. Stack, pin, and drag assets into any app with zero friction.
Download for Windows Get from Microsoft Store
How to Install Guide · First 10 Minutes Guide · Drag & Drop Guide · Edge Drop vs Win+V · Support
Free · Lightweight · Privacy First