Created
January 16, 2021 12:14
-
-
Save yyano/c32a8ddd8e40c9af70405373651065d4 to your computer and use it in GitHub Desktop.
PowerShellで重複してると思われるファイル・フォルダを調整(削除・コピー)する
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
# 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