A first approach to solve the problem could be to pass the starting root and do not delete the directory if it is the starting root
Public Sub DeleteEmptyFolders(ByVal sPath As String, ByVal sRoot As String)
Dim SubDirectories() As String = Directory.GetDirectories(sPath )
For Each strDirectory As String In SubDirectories
DeleteEmptyFolders(strDirectory, sRoot)
Next
If Not (UCase(Path.GetDirectoryName(sPath)).Contains("BACKUP")) Or (UCase(Path.GetDirectoryName(sPath)).Contains("BARS")) Then
If Directory.GetFiles(sPath).Length + Directory.GetDirectories(sPath).Length = 0 Then
if sPath <> sRoot Then
Directory.Delete(sPath)
Console.WriteLine("Deleting empty folder: " & sPath)
End If
End If
End If
End Sub
Call with
DeleteEmptyFolders("D:\temp", "D:\temp")