【发布时间】:2018-03-10 17:47:33
【问题描述】:
我有这个脚本可以搜索相同大小的文件,如果它的大小相同,我让一个文件在它所在的位置(“C:\folder1”)并将其他副本移动到“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'
}
}
现在的问题是我想这样做,但只使用文件夹,而不是文件。
我尝试放置 -Directory 而不是文件,但我不知道下一步该做什么。
$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-FileHash -Path $Path).Hash
标签: powershell compare