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
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!
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.
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.
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
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically