I have two parent directories that each have several subdirectories. Inside those subdirectories are several files, but I am only interested in .inf files. Basically, one of the parent directories has a lot of extra subdirectories that are not needed, that contain .inf files that are of no interest to me. So, I would like to be prompted for the path of each parent directory. After that, I will need to find all .inf files in the first parent directory. For each of those .inf files found, I need to find a matching .inf in the second parent directory. I want to keep the subdirectory where the matching .inf file is found. I want to delete all of the extra subdirectories where matching .inf files are not found in the second parent directory. Note that the subdirectory names are not the same in both parent directories. Here is an example of the folder structures.
$dir1
-dptf
–drivers
—x64
----a bunch of files, including .inf files
–lang
–mup
-fngprint
–drivers
—WBF_0010_DRV
----wbf_vfs_0010.cat
----wbf_vfs_0010.inf
$dir2
-dptf_acpi.inf_amd64_143446f307e3b92f
–bunch of file, including .inf files
-e1c65x64.inf_amd64_afcffd22d02c62f9
–bunch of files, including .inf files
This isnt much, but here is what I started with:
$dir1 = Read-Host 'What is the path of the first directory?' $dir2 = Read-Host 'What is the path of the second directory?' Get-ChildItem -Path $dir1 -Filter *.inf -Recurse -File -Name | ForEach-Object { [System.IO.Path]::GetFileName($_) }