-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find-DuplicateFiles.ps1
35 lines (31 loc) · 1.11 KB
/
Find-DuplicateFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#
Finds duplicate files from one directory in another directory structure.
Only compares file names and file lengths.
#>
param(
[Parameter(Mandatory=$true)]
[string]
$SourceDirectory,
[Parameter(Mandatory=$true)]
[string]
$PotentialDuplicateDirectory)
$sourceFiles = Get-ChildItem $SourceDirectory
$potentialDuplicateFiles = Get-ChildItem $PotentialDuplicateDirectory -Recurse
$OnlyCompareFileNames = $true
foreach ($file in $sourceFiles)
{
foreach ($potentialDuplicateFile in $potentialDuplicateFiles)
{
if ($potentialDuplicateFile.Name -eq $file.Name)
{
if ($true)
{
Write-Output "Found file $($potentialDuplicateFile.Name) in $($potentialDuplicateFile.DirectoryName) as a duplicate"
}
else
{
Write-Warning "Found file $($potentialDuplicateFile.Name) in $($potentialDuplicateFile.DirectoryName) with length $([int]($persistentFile.Length / (1024 * 1024))) MB but a source length of $([int]($file.Length / (1024 * 1024))) MB."
}
}
}
}