项目作者: theohbrothers

项目描述 :
Gets duplicate or non-duplicate files.
高级语言: PowerShell
项目地址: git://github.com/theohbrothers/Get-DuplicateItem.git
创建时间: 2018-06-14T05:33:38Z
项目社区:https://github.com/theohbrothers/Get-DuplicateItem

开源协议:Apache License 2.0

下载


Get-DuplicateItem

github-actions
github-release
powershell-gallery-release

Gets duplicate or non-duplicate files.

Install

Open powershell or pwsh and type:

  1. Install-Module -Name Get-DuplicateItem -Repository PSGallery -Scope CurrentUser -Verbose

Usage

The cmdlet supports the same parameters as Get-ChildItem: -Path, -LiteralPath, -Include, -Exclude, and -Recurse.

Use the -AsHashtable switch to get a hashtable containing [string]$md5 = [System.Collections.ArrayList]$files.

  1. # Get duplicate files in 'C:/folder1' only
  2. Get-DuplicateItem -Path 'C:/folder1'
  3. # Alternatively, you may pipe folder paths
  4. 'C:/folder1' | Get-DuplicateItem
  5. # Or DirectoryInfo objects
  6. Get-Item 'C:/folder1' | Get-DuplicateItem
  7. # Get duplicate files in 'C:/folder1' and its descendents
  8. Get-DuplicateItem -Path 'C:/folder1' -Recurse
  9. # Get duplicate files in 'C:/folder1' and its descendents in the form: hash => FileInfo[]
  10. Get-DuplicateItem -Path 'C:/folder1' -Recurse -AsHashtable
  11. # Remove all duplicate items
  12. Get-DuplicateItem -Path 'C:/folder1' | Remove-Item
  13. # Remove all duplicate files in 'C:/folder1' and its descendents
  14. Get-DuplicateItem -Path 'C:/folder1' -Recurse | Remove-Item

Use the -Inverse switch to get non-duplicates.

  1. # Get non-duplicate files in 'C:/folder1' only
  2. Get-DuplicateItem -Path 'C:/folder1' -Inverse
  3. # Get non-duplicate files in 'C:/folder1' and its descendents
  4. Get-DuplicateItem -Path 'C:/folder1' -Inverse -Recurse
  5. # Get non-duplicate files in 'C:/folder1' and its descendents in the form: hash => FileInfo[]
  6. Get-DuplicateItem -Path 'C:/folder1' -Inverse -Recurse -AsHashtable
  7. # Remove all non-duplicate files in 'C:/folder1' only
  8. Get-DuplicateItem -Path 'C:/folder1' -Inverse | Remove-Item
  9. # Remove all non-duplicate files in 'C:/folder1' and its descendents
  10. Get-DuplicateItem -Path 'C:/folder1' -Inverse -Recurse | Remove-Item

Notes

The cmdlet calculates the md5 hash of each descendent file, to be able to identify duplicates and non-duplicates. Therefore if there are many large descendent files, it is normal for the Cmdlet to take several seconds to several minutes to complete.