Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Created July 28, 2024 08:28
Show Gist options
  • Select an option

  • Save HirbodBehnam/b86d4b6318c47bf9b80fbd1ec08906a0 to your computer and use it in GitHub Desktop.

Select an option

Save HirbodBehnam/b86d4b6318c47bf9b80fbd1ec08906a0 to your computer and use it in GitHub Desktop.

Revisions

  1. HirbodBehnam created this gist Jul 28, 2024.
    15 changes: 15 additions & 0 deletions dedup.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # 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
    }
    }