Skip to content

Instantly share code, notes, and snippets.

@yyano
Created January 16, 2021 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyano/c32a8ddd8e40c9af70405373651065d4 to your computer and use it in GitHub Desktop.
Save yyano/c32a8ddd8e40c9af70405373651065d4 to your computer and use it in GitHub Desktop.
PowerShellで重複してると思われるファイル・フォルダを調整(削除・コピー)する
# Google dirveの同期などでファイルの重複が発生してしまったときに
# (1)がつくファイルとつかない同じ名前のファイルをhash比較して、同じときに(1)がつくファイルを削除する
#
Get-ChildItem . -Recurse -Filter '* (1)*' -File |
ForEach-object -Process {
$orgFile = $_.FullName.Replace(" (1).", ".")
Write-Host $_.FullName
if( (Get-FileHash -Algorithm md5 $orgFile).Hash -eq (Get-FileHash -Algorithm md5 $_.FullName).Hash )
{
Write-Host "=, remove file"
Remove-Item $_.FullName
} else {
Write-Host "<>"
Get-FileHash -Algorithm md5 $orgFile
Get-FileHash -Algorithm md5 $_.FullName
}
}
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment