Small quality-of-life thing: on Windows you can copy a file/folder path, but it looks like this:
C:\Users\you\projects
If you’re working with WSL, Docker, or Linux tools, it’s nicer as:
/mnt/c/Users/you/projects
This guide adds a right-click context menu entry in File Explorer called:
Copy as Linux Path
When you click it on a file, folder, or empty space in a folder, it copies a WSL-style path to the clipboard.
It does:
-
Add three context-menu items (file, folder, background)
-
Call a PowerShell script that:
- Converts
C:\something→/mnt/c/something - Handles drive roots (
C:\→/mnt/c) - Handles UNC paths (
\\server\share\foo→/mnt/unc/server/share/foo) - Copies the result to the clipboard
- Converts
It does not:
- Change file associations
- Touch boot settings or system services
- Modify anything outside the
shellkeys in the registry
If you remove the registry keys, it’s gone.
- Windows 10/11
- PowerShell (built in)
- Admin rights (to import the
.regfile) - Any text editor
I’ll assume we’re using this folder for the script:
C:\Scripts\
Feel free to change that, just keep the .reg file in sync.
Create a file:
C:\Scripts\CopyAsLinuxPath.ps1
Paste this inside:
param(
[string[]]$TargetPath
)
function Convert-ToLinuxPath {
param(
[string]$Path
)
if (-not $Path) {
return $null
}
try {
# Normalize to a full path when possible
$normalized = [System.IO.Path]::GetFullPath($Path)
}
catch {
# If GetFullPath fails (weird input), just use whatever we got
$normalized = $Path
}
# UNC paths: \\server\share\folder → /mnt/unc/server/share/folder
if ($normalized.StartsWith("\\\")) {
$trimmed = $normalized.TrimStart("\")
$rest = $trimmed -replace '\\','/'
return "/mnt/unc/$rest"
}
# Drive-letter paths: C:\something → /mnt/c/something
if ($normalized -match '^(?<drive>[A-Za-z]):\\(?<rest>.*)$') {
$drive = $Matches['drive'].ToLower()
$rest = $Matches['rest'] -replace '\\','/'
if ([string]::IsNullOrEmpty($rest)) {
# Root of drive, e.g. C:\
return "/mnt/$drive"
}
else {
return "/mnt/$drive/$rest"
}
}
# Fallback: just swap slashes
return ($normalized -replace '\\','/')
}
# If nothing was passed, fall back to the current directory
if (-not $TargetPath -or $TargetPath.Count -eq 0) {
$TargetPath = @(Get-Location)
}
$linuxPaths = @()
foreach ($p in $TargetPath) {
$lp = Convert-ToLinuxPath -Path $p
if ($lp) {
$linuxPaths += $lp
}
}
if ($linuxPaths.Count -gt 0) {
$text = $linuxPaths -join "`r`n"
try {
Set-Clipboard -Value $text
}
catch {
# Worst case: clipboard fails, we just swallow it
}
}Save the file.
If you put this somewhere else, remember the full path; we’ll need it in the next step.
Create another file somewhere (Desktop is fine):
Add_CopyAsLinuxPath.reg
Paste this:
Windows Registry Editor Version 5.00
; ----- File right-click: Copy as Linux Path -----
[HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%1\""
; ----- Folder right-click: Copy as Linux Path -----
[HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%1\""
; ----- Background right-click (inside a folder): Copy as Linux Path -----
[HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%V\""If your script isn’t in C:\Scripts\CopyAsLinuxPath.ps1, update all three paths accordingly.
If you’re nervous about the registry (fair), do this:
-
Press
Win + R, typeregedit, hit Enter. -
Go to:
HKEY_CLASSES_ROOT\*\shellHKEY_CLASSES_ROOT\Directory\shellHKEY_CLASSES_ROOT\Directory\Background\shell
-
Right-click each
shellkey → Export → save somewhere as a backup.
If you ever want to revert, you can just double-click those backups.
- Double-click
Add_CopyAsLinuxPath.reg. - Say Yes to the UAC and registry prompts.
- That’s it. You don’t need to reboot or log out.
Open File Explorer and try three things:
-
Right-click a folder → “Copy as Linux Path”
- Paste somewhere (Notepad, VS Code, etc.)
- Expected: something like
/mnt/c/Users/you/SomeFolder
-
Right-click a file → “Copy as Linux Path”
- Expected:
/mnt/c/Users/you/SomeFolder/file.txt
- Expected:
-
Right-click on empty space inside a folder → “Copy as Linux Path”
- Expected: path to that folder as
/mnt/...
- Expected: path to that folder as
If you get a PowerShell error popup instead, it’s usually:
- The script path in the
.regfile doesn’t match where the script actually is. - Or the script had a copy/paste issue (missing quote, etc.).
Fix the path or re-paste the script and try again.
If you don’t want this anymore, you can nuke it cleanly.
Create a file:
Remove_CopyAsLinuxPath.reg
Paste this:
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath]
[-HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath]Save → double-click → confirm.
The “Copy as Linux Path” entries will disappear from the context menu.
Just delete:
C:\Scripts\CopyAsLinuxPath.ps1
Done.
-
Drive roots
C:\→/mnt/cD:\→/mnt/d -
Network paths
\\server\share\folder→/mnt/unc/server/share/folderThis isn’t an official WSL standard, but it’s a reasonable convention and easy to tweak in the script if you want something else. -
Weird input The script tries
GetFullPath()but catches errors. Worst case, it just swaps backslashes for forward slashes. -
Multiple items The script can handle multiple paths (it joins them with newlines), but the default context menu wiring here passes one item. If you want to wire it up for multi-select in a different way later, the script is already ready for it.
You can modify the PowerShell script to:
- Show a toast / popup with the copied path.
- Automatically open WSL with that path.
- Format paths for Docker volumes, etc.
But the base setup above should be safe, simple, and GitHub-gist-friendly.
That’s it. Drop this into a gist and you’ve got a handy little “Copy as Linux Path” helper for Windows.