Find folders that don't contain a file

Hi,

I am trying to get a list of all folders in my music collection that do not have a file called ‘folder.jpg’. I have come up with this, but it still shows folders that do contain 'folder.jpg.

Clear-Host
$ThePath = "$Env:USERPROFILE\CloudStation" #Change this
Get-ChildItem -Path $ThePath -Recurse |
    Where-Object { ($_.PSIsContainer -eq $True) -and ($_.Name -notlike "folder.jpg") } |
    Sort-Object FullName | Select-Object FullName | Format-Table * -AutoSize

I know the issue is with the statement [$_.Name -notlike “folder.jpg”] as I think it is looking for a Folder named called folder.jpg, but I’m nt sure on what syntax I should be using.

Thanks
Tony

Hi.

You are testing for folders not named folder.jpg.

You can try this snippet to return only the folders that does not contain a file named folder.jpg

Clear-Host
$ThePath = "$Env:USERPROFILE\CloudStation" #Change this
$dirs = Get-ChildItem -Path $ThePath -Recurse -Directory

foreach ($dir In $dirs.Fullname) {
    if(-not(Test-Path "$dir/folder.jpg")) {
        Write-Output $dir
    }
}

Stein

Thanks Stein