Figure out what files are missing from two paths in your Windows Machine using Powershell
Sometimes you just miss the spot and while you want to have the same names on files for two different folders and you would like to do it the geek way
In this article, I will comment step by step on how to figure out what file is missing from one folder that another folder has. Individually, I’ve been working on 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??
My name is Jose Ortega, and I’m a Microsoft Certified Solution Expert on Messaging and Windows Server; also I have been working for Microsoft Gold Partners for about 12 years. I used to post my script on Technet until MS decided to shut it down, now I moved to Medium. Thank you in advance for all the support, donations, and comments you’ve been left for me to keep doing this, a piece of my heart will be on you.
The Solution for the different extensions 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
Because I know you love oneliner what about one for this?
Compare-Object -ReferenceObject $(gci "D:\Chiapas\timelapse2 02072020\Capture") -DifferenceObject $(gci "D:\Chiapas\timelapse2 02072020\Output")
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, if this article was useful in any way, Let me know in a comment if you have questions, suggestions for new articles, or want to say HI. You can contact me directly using email or MS Teams firstname.lastname@example.org; Cheers!