How can I compare two folders to find missing files?

0
6
Asked By AudioExplorer42 On

Hey everyone! I'm trying to compare two folders that contain a lot of subfolders to identify any missing files. I recently converted around 25,000 audio files, but some of them didn't transfer over to the output folder. The original files had various formats (like FLAC, MP3, M4A, WAV, OGG), but the converted ones are all in OGG format. Even though the file names and their locations within the folders should match, I'm having trouble figuring out which ones are missing. Any advice on how to tackle this? Thanks! 🙂

4 Answers

Answered By FileMaster321 On

If you want something more visual than command line, check out Beyond Compare from Scooter Software. It’s not PowerShell, but it can be scripted and is by far the best comparison tool I’ve used!

Answered By CodeWizard007 On

Have you tried running any code yet? It might help if you share what you've implemented so far so others can give targeted help.

Answered By TechGuru99 On

You can use PowerShell to compare the two folders easily. Just use these commands:

```powershell
$SourceFiles = Get-ChildItem -path $SourcePath -Recurse
$TargetFiles = Get-ChildItem -path $TargetPath -Recurse
$Missing = Compare-Object -ReferenceObject $SourceFiles -DifferenceObject $TargetFiles -Property BaseName
```

This will help you identify which files from your source are missing in the target.

Answered By ScriptNinja On

Here’s a neat little script that might work for you:

```powershell
$folderA = "C:filesFolderA"
$folderB = "C:filesFolderB"

function Get-RelativePathNoExt {
param ([string]$basePath, [string]$fullPath)
$relativePath = $fullPath.Substring($basePath.Length).TrimStart('')
[System.IO.Path]::ChangeExtension($relativePath, $null)
}

$filesA = Get-ChildItem -Path $folderA -Recurse -File
$filesB = Get-ChildItem -Path $folderB -Recurse -File

$setA = $filesA | ForEach-Object { Get-RelativePathNoExt -basePath $folderA -fullPath $_.FullName }
$setB = $filesB | ForEach-Object { Get-RelativePathNoExt -basePath $folderB -fullPath $_.FullName }

diff = $setB | Where-Object { $_ -notin $setA }

Write-Host "Files in $folderA but not in $folderB :"
$diff | ForEach-Object { Write-Host $_ }
```

This should give you a list of files that are missing in your output folder.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.