SCRIPT: check if folder is empty
‘vbscript
Option Explicit
Dim oFS : Set oFS = CreateObject(“Scripting.FileSystemObject”)
Function FolderEmpty(strFolderPathName)
Dim oFiles, oFile, oFolder, oSubFolders, oSubFolder
Dim blnFileFound : blnFileFound = False
Set oFolder = oFS.GetFolder(strFolderPathName)
Set oFiles = oFolder.Files
If oFiles.Count > 0 Then
FolderEmpty = False
Exit Function
End If
Set oSubFolders = oFolder.SubFolders
For Each oSubFolder In oSubFolders
If Not FolderEmpty(oSubFolder.Path) Then
FolderEmpty = False
Exit Function
End If
Next
FolderEmpty = True
End Function
Dim strFolderPathName1 : strFolderPathName1 = “file://server/c$/folder“
If FolderEmpty(strFolderPathName1) Then
MsgBox “the folder ” & strFolderPathName1 & ” is empty”
Else
MsgBox “the folder ” & strFolderPathName1 & ” is not empty”
End If