Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 比较文件夹大小并移动到其他文件夹_Powershell_Compare - Fatal编程技术网

Powershell 比较文件夹大小并移动到其他文件夹

Powershell 比较文件夹大小并移动到其他文件夹,powershell,compare,Powershell,Compare,我有一个脚本,可以搜索相同大小的文件,如果大小相同,我会将其中一个放在原处(“C:\folder1”),并将其他副本移动到“C:\files\u” 现在的问题是,我想这样做,但只与文件夹,而不是文件了 我试着把目录改成文件,但我不知道下一步该怎么办 $allfiles = Get-ChildItem -Directory -recurse "C:\folder1" | Group-Object -Property length foreach($filegroup in $allfiles)

我有一个脚本,可以搜索相同大小的文件,如果大小相同,我会将其中一个放在原处(“C:\folder1”),并将其他副本移动到“C:\files\u”

现在的问题是,我想这样做,但只与文件夹,而不是文件了

我试着把目录改成文件,但我不知道下一步该怎么办

$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'
    }
}

谢谢。

您可以使用它,它会比较文件夹中的文件,如果文件长度相同,它会移动到目标文件夹

Get-ChildItem -file "E:\folder" | Group-Object -Property length | ForEach-Object {$_.Group | Select-Object -Skip 1 | Move-Item -Destination "E:\folder\move"}

不比较文件大小:比较文件哈希<代码>(getfilehash-Path$Path)。Hash我很感激。作为一般提示:考虑将长管道分布到多行以提高可读性,如果在每个管道符号(
|
)后断开该行,则直接支持该操作(无需行尾转义字符)。
`
)。
Get-ChildItem -file "E:\folder" | Group-Object -Property length | ForEach-Object {$_.Group | Select-Object -Skip 1 | Move-Item -Destination "E:\folder\move"}