Reputation: 55
I have this script that searches for files of the same size and if it is of the same size I let one where it is ("C:\folder1") and move the others copies to the "C:\files_compared".
$allfiles = Get-ChildItem -file -recurse "C:\folder1" | Group-Object -Property length
foreach($filegroup in $allfiles)
{
if ($filegroup.Count -ne 1)
{
$fileGroup.Group[1..($fileGroup.Count-1)] | move -Destination 'C:\Files_compared'
}
}
The problem now is that I want to do this but only with folders, not files anymore.
I tried to put the -Directory instead of file but I don't know what to do next.
$allfiles = Get-ChildItem -Directory -recurse "C:\folder1" | Group-Object -Property length
foreach($filegroup in $allfiles)
{
if ($filegroup.Count -ne 1)
{
$fileGroup.Group[1..($fileGroup.Count-1)] | move -Destination 'C:\Files_compared'
}
}
Thanks.
Upvotes: 0
Views: 166
Reputation: 75
You can use this, It compares a files in a folder and it moves to destinations folder if file length is same.
Get-ChildItem -file "E:\folder" | Group-Object -Property length | ForEach-Object {$_.Group | Select-Object -Skip 1 | Move-Item -Destination "E:\folder\move"}
Upvotes: 1