I am trying to locate via PowerShell or other method zip files and folders that have same name.
Staff members unpack their zip files on our storage array and subsequently never delete the zip file. Now we have two copies, the zip file and the unzipped folder.
Via PowerShell, I could find a text and zip file that have the same name, but not a folder and a zip file.
Any help is appreciated. Below is my code.
Get-ChildItem -Path c:\temp\test -Recurse | Group-Object -Property Directory, BaseName | Where-Object Count -gt 1 | Select-Object Name
CodePudding user response:
Assuming I understood correctly, here is one way you could do it. See inline comments to help you understand the logic.
# find all `.zip` files recursively
Get-ChildItem c:\temp\test -Filter *.zip -Recurse |
# where the Parent Directory of this file also has a sub-folder
# with the same `.BaseName` as this `.zip` file :)
Where-Object { $_.Directory.EnumerateDirectories($_.BaseName) }