← Back to Blog

Developers & Code | Published Aug 21, 2026 | Updated Oct 13, 2026 | 6 min read

How to Copy a File Path That Works in the Terminal

By Deepender Yadav

How to Copy a File Path That Works in the Terminal — Edge Drop Guide

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 pasteWhat to useExample
Command PromptThe copied path as-istype "C:\Users\Sam\My Project\app.log"
PowerShell (argument)As-is; single quotes if the path has $ or a backtickGet-Content 'C:\Users\Sam\$work\app.log'
PowerShell (run a program)& before the quoted path& "C:\Program Files\Tool\tool.exe" --version
Git BashSingle quotes, or convert with cygpathcygpath -u 'C:\Users\Sam\My Project'
WSLConvert with wslpathwslpath 'C:\Users\Sam\My Project'
PythonA raw stringr"C:\Users\Sam\My Project\app.log"
JSONDouble 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 $name as a variable, so a folder called $work silently becomes something else. Wrap paths that contain $ or a backtick in single quotes, which PowerShell treats literally.
  • Square brackets. -Path treats [ and ] as wildcard characters, so C:\Logs\[old]\app.log may not match. Use -LiteralPath instead: 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:

  1. Use single quotes. Bash keeps everything inside single quotes literally: ls -l 'C:\Users\Sam\My Project'.
  2. 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.exe becomes the command C:\Program with Files\Tool\tool.exe as its argument.
  • Very long paths: many Windows tools still stop at the classic 260-character MAX_PATH limit, 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 a C:\... 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

Sources

Deepender Yadav
Written by Deepender Yadav · Creator & Developer

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 · LinkedIn

Copy. 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
Find us on CodeHype