Forked from ipcjs/+Windows 10 Add Copy-Paste as Symbolic Link or Junction.md
Last active
September 8, 2021 12:44
-
-
Save zer0k-z/6157ca64d725debca34229af18298559 to your computer and use it in GitHub Desktop.
Windows 10 Add Copy-Paste as Relative Symbolic Link or Junction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add windows Explorer Right-Click menu to paste copied item as Relative SymbolicLink with PowerShell | |
# Locate file on C:\cmd\ | |
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 { | |
$rpath = Resolve-Path -Path $file -Relative | |
# 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 $rpath | |
} | |
else { | |
# Write-Output "file" | |
cmd /c mklink $file.name $rpath | |
} | |
# Pause | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\symlinkpaste] | |
@="Paste Symlink (Relative)" | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\symlinkpaste\command] | |
@="cmd /c start /min \"\" powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\CMD\\paste-symlink-relative.ps1\" -location \"%V\" " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment