English: Add a menu item of Paste Symlink
to the Windows right-click menu
中文:给Windows的右键菜单添加粘贴成符号链接
的菜单项
# Add windows Explorer Right-Click menu to paste copied item as SymbolicLink with PowerShell | |
# Locate file on D:\GitHub\gist\82e4385532be90eac99546df99a2854d\ | |
param ( | |
[Parameter(Mandatory = $true)][string]$location | |
) | |
Set-Location $location | |
$files = Get-Clipboard -Format FileDropList | |
$count = $files.count; | |
if ($count -eq 0) { | |
Write-Output "No file(s) in clipboard" | |
Pause | |
} | |
else { | |
Write-Output "Making Junction/Link of $count files" | |
foreach ($file in $files) { | |
if ( (Test-Path $file.Name) -eq $true ) { | |
Write-Output "$($file.Name) Exists" | |
Pause | |
} | |
else { | |
# When enable develper mode, New-Item require admin on some computer, but mklink no require... why?!! | |
# New-Item -ItemType SymbolicLink -Name $file.name -Target $file | |
# `file.Attributes` to check path is a directory is invalid on some computer...replace to `Test-Path`. | |
# if ($file.Attributes -eq 'Directory') { | |
if ((Test-Path $file -PathType Container) -eq $true) { | |
# Write-Output "dir" | |
cmd /c mklink /d $file.name $file | |
} | |
else { | |
# Write-Output "file" | |
cmd /c mklink $file.name $file | |
} | |
# Pause | |
} | |
} | |
} |
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\1_PasteSymlink] | |
@="Paste Symlink" | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\1_PasteSymlink\command] | |
@="powershell.exe -File \"C:\\GitHub\\gist\\82e4385532be90eac99546df99a2854d\\paste-symlink.ps1\" -location \"%V\"" | |