-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find-MissingFilesByReference.ps1
49 lines (42 loc) · 1.25 KB
/
Find-MissingFilesByReference.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
Finds all files which don't exist, given a list of filenames (without extensions) and a persistent directory where the files should be stored.
#>
param(
#[Parameter(Mandatory=$true)]
[string]
$FilenamesFile, # This should be a newline-deliminated list
#[Parameter(Mandatory=$true)]
[string]
$PersistentDirectory)
$sourceFiles = [IO.File]::ReadAllLines($FilenamesFile)
$existingFiles = Get-ChildItem $PersistentDirectory -Recurse
$foundFiles = 0
$parsedFiles = 0
Write-Output "Read in $($sourceFiles.Count) file names to search for."
foreach ($filename in $sourceFiles)
{
# Inefficient, but good enough for the scale of files I'm using.
$foundFile = $false
foreach ($existingFile in $existingFiles)
{
if ([IO.Path]::GetFileNameWithoutExtension($existingFile.Name.ToString()).Equals($filename, [StringComparison]::OrdinalIgnoreCase))
{
$foundFile = $true
break
}
}
if (-not $foundFile)
{
Write-Output $filename
}
else
{
++$foundFiles
}
++$parsedFiles
if ($parsedFiles % 50 -eq 0)
{
Write-Output "-- $parsedFiles of $($sourceFiles.Count)"
}
}
Write-Output "$($sourceFiles.Count) total files, $foundFiles files found."