Jack
Jack

Reputation: 317

finding folder without certain file in powershell

I have subfolders, and subsubfolders. In the subsubfolders, I want to find all subfolders without a file named PKA.dump. Can this be done in powershell?

The subfolders go from Angle1, Angle2, etc up to Angle24

The subsubfolders go from 1eV, 2eV, to 150eV.

I can find when they are less than a certain size:

Get-Childitem -path .  -filter "PKA.dump" -recurse | where {$_.Length -le 500}

But what if they dont exist?

Upvotes: 1

Views: 835

Answers (2)

Paul
Paul

Reputation: 5861

For a deeper folder structure this should be ok:

Get-ChildItem -Path C:\yourpath\ -recurse | where {$_.psiscontainer} | % {
if((Get-ChildItem -Path $_.FullName -File).name -notcontains "pka.dump"){ $_.FullName }
}

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

If you have just 2 levels of directories, don't recurse. Do something like this instead:

Get-ChildItem -Path . -Directory | Get-ChildItem -Directory | ? {
  -not (Test-Path -LiteralPath (Join-Path $_.FullName 'PKA.dump'))
}

Upvotes: 3

Related Questions