Figure out what files are missing from two paths in your Windows Machine using Powershell
In this article, I will comment step by step how to figure out what file is missing from one folder that another folder has it. Individually, I’ve been working processing files for hours, and now I got 599 records in one folder (all files with extension ARW). I got 598 files on another one (with extensions JPG), and I need to find out using PowerShell. What’s the file missing??
The Solution for the different extension is to compare the basename of the files attribute, which will be the same between them.
$l1=gci -File -Path $path1 | select -ExpandProperty Basename
$l2=gci -File -Path $path2 | select -ExpandProperty baseName
Compare-Object -ReferenceObject $l1 -DifferenceObject $l2
If all the files from path1 are in path2, you will get no output
If on the other hand there are more files on $path2 than in $path1 you’ll get something like this:
This indicates that the file _7R36959 is present on $l2 (that’s why the SideIndicator goes from ReferenceObject to DifferenceObject (=>). This says that there are more pictures revealed than the source, and it’s an impossible case.
To simulate this, I’ve moved the picture _7R36959.ARW to another folder.
The other case is more files on the source than the target (which is the expected result if you’re missing to post-process a picture).
This indicates that the file _7R36959 is present on $l1 (source), the side indicators go from referenceObject $l1 to differenceObject $l2 (<=)
Thank you very much for reading!