Created
July 28, 2024 08:28
-
-
Save HirbodBehnam/b86d4b6318c47bf9b80fbd1ec08906a0 to your computer and use it in GitHub Desktop.
Deduplicate files with symbolic links
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
# Use https://github.com/sreedevk/deduplicator then use | |
# jq 'map(. + {key: (.hash + (.size | tostring))}) | group_by(.key) | map([.[] | .path[22:]])' dup.json | |
# to get the changed.json file. | |
# The script must be ran as admin. | |
$a = cat changed.json | ConvertFrom-Json | |
foreach ($duplicate_files in $a) | |
{ | |
foreach ($file in ($duplicate_files | Select-Object -Skip 1)) { | |
Write-Host "Deleting", $file | |
Remove-Item $file | |
$relative_path = [IO.Path]::GetRelativePath([IO.Path]::GetDirectoryName($file), $duplicate_files[0]) | |
Write-Host "Linking", $file, "to", $relative_path | |
cmd /c mklink $file $relative_path | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment