# Find an Empty Folder / Latest Empty Folder

**URL:** <https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050>\
**Category:** PowerShell Help\
**Created:** [March 21, 2016, 11:52pm UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050 "2016-03-21T23:52:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![robb-delaney](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robb-delaney](https://forums.powershell.org/u/robb-delaney)\
**Post date:** [March 21, 2016, 11:52pm UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/1 "2016-03-21T23:52:51Z")

</div>

New the forum, and new to powershell, so here goes…

I have a audio call recorder that places calls in a numbered folders that contain .wav files  
If the folder is empty… that is bad…

1. Each server has a G:\Calls directory.
2. Each server is unique, they have an individual folder name under the calls directory, for example: G:\Calls\722057
3. To further complicate things… there are several other folders deeper in that directory. Example: G:\Calls\722057\012\87\75

What I need to do is verify the LATEST folder in the directory contains a .wav file or is NOT empty without knowing the explicit name of the folder under G:\Calls.

I am pretty sure I am going to have to use Powershell or something, just wanted to see if anyone has done this before…

Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![bobmccoy](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bobmccoy/32/650_2.png) [@bobmccoy](https://forums.powershell.org/u/bobmccoy)\
**Post date:** [March 22, 2016, 1:43am UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/2 "2016-03-22T01:43:53Z")

</div>

Define “LATEST”. Is that the time the folder was created, or the time it was last written to?

---

<div class="post-metadata">

**Author:** ![robb-delaney](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robb-delaney](https://forums.powershell.org/u/robb-delaney)\
**Post date:** [March 22, 2016, 2:16am UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/3 "2016-03-22T02:16:57Z")

</div>

![Smiley face](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/a/ab48c5d0b9c11aeb3edad0b58432f9b5c9854588.png)

That is an example of the directory structure.  
G:\Calls  
G:\Calls\722057 (Date Modified 1/22/2015 at 9:25 am)  
(this 722057 folder is unique and dated on all servers and contains newer folders beneath it. for example"

G:\Calls\722057\017\82\00\ (Date Modified 3/22/2016 at 9:25 am)  
G:\Calls\722057\017\82\01\ (Date Modified 3/22/2016 at 9:30 am)  
G:\Calls\722057\017\82\02\ (Date Modified 3/22/2016 at 9:35 am)

I would need to search G:\Calls to find the latest folder in that directory after that unique one without explicitly calling out that unique folder.

---

<div class="post-metadata">

**Author:** ![wilfredo-perez](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@wilfredo-perez](https://forums.powershell.org/u/wilfredo-perez)\
**Post date:** [March 23, 2016, 6:26am UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/4 "2016-03-23T06:26:36Z")

</div>

Are you looking for something like this:

```
Get-ChildItem G:\Calls -Recurse -Filter "*.wav"
```

The script will look at all the file within G:\Calls and just display the wav file.

I ran this script:  
PS C:\WINDOWS\system32\> Get-ChildItem C:\Calls -Recurse -Filter “\*.wav”

the file was found in - C:\Calls\018  
Mode LastWriteTime Length Name

* * *

-a---- 3/23/2016 3:50 PM 0 New.wav

---

<div class="post-metadata">

**Author:** ![robb-delaney](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robb-delaney](https://forums.powershell.org/u/robb-delaney)\
**Post date:** [March 23, 2016, 9:54pm UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/5 "2016-03-23T21:54:40Z")

</div>

Actually, I am looking to find the EMPTY folder, if one exists… in the sub-directory.

an EMPTY folder would mean there is a problem.

Thank you!

---

<div class="post-metadata">

**Author:** ![wilfredo-perez](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@wilfredo-perez](https://forums.powershell.org/u/wilfredo-perez)\
**Post date:** [March 24, 2016, 3:35am UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/6 "2016-03-24T03:35:50Z")

</div>

Try this:

```
Get-ChildItem C:\Calls -Recurse | where {$_.Attributes -eq 'Directory'} | where $_.Getfiles().Count -eq 0 | select Name
```

You will have to change the location from C:\Calls to G:\Calls

---

<div class="post-metadata">

**Author:** ![robb-delaney](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robb-delaney](https://forums.powershell.org/u/robb-delaney)\
**Post date:** [March 24, 2016, 7:14am UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/7 "2016-03-24T07:14:03Z")

</div>

CDuff helped me with a solution on this  
because the folder structure is always 5 levels deep… it searches past all the folders that are less than an hour old and throws a message when it finds an empty folder.

`
$root = "T:\Calls\*\*\*\*"
$folders = Get-Item -Path $root |
Where-Object {
    $_.CreationTime -gt (Get-Date).AddHours(-1)
} |
Where-Object {
    -not (
        $_ | Get-ChildItem -Filter '*.wav'
    )
}
If($folders) {
Write-Output “Do your notification here”
`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/find-an-empty-folder-latest-empty-folder/6050/8 "2024-05-16T20:41:44Z")

</div>

Closed on May 16, 2024, 8:41pm UTC


