Find an Empty Folder / Latest Empty Folder

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!

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

Smiley face

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.

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

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!

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

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”