Figure out what files are missing from two paths in your Windows Machine using Powershell
Sometimes you 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 figuring out what file is missing from one folder that another has. Individually, I’ve been working on processing files for hours, and now I have 599 records in one folder (all files with extension ARW). I got 598 files on another one (with extensions JPG), and I need to learn using PowerShell. What’s the file missing??
My name is Jose Ortega, and I’m a Microsoft Certified Professional on Office 365, Powershell, Messaging (Exchange Online/Exchange On-premises), and Windows Server. I’ve been working with Microsoft Technologies for 12+ years and independently since 2015 using Upwork and reaching the distinction of Top-Rated Plus Freelancer. I used to write scripts for TechNet in my free time, but now I’ve moved to Medium; my goal is to help you solve complicated and straightforward problems with my experience. You can expect an article from one to three weeks. Right now, I’m working and assisting on a Microsoft GIG as a freelancer for Office365 tickets and customers worldwide. Thank you in advance for all the support, follow, clap, comment, and donation. If you would like to ask something or discuss it further, please reach me on social networks (Twitter, Instagram, Facebook, or GitHub as j0rt3g4).
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 arrow says that more pictures are 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 (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. Any comments you can contact me over social networks (Twitter, Instagram, Facebook, or GitHub as j0rt3g4), or over teams/email if you prefer firstname.lastname@example.org. I want to know from you, leave your comments or doubts and share this information if you think it was helpful in any way for you.