Fixed removing empty sub-folders

This commit is contained in:
MikeMaximus
2018-07-02 08:39:16 -06:00
parent 1f9dc18c49
commit 017c5def56
2 changed files with 17 additions and 9 deletions
+15 -8
View File
@@ -434,15 +434,22 @@ Public Class mgrCommon
Dim oDir As DirectoryInfo
Dim sDir As String = sBackupFolder & oBackup.MonitorID
'Delete sub directory if it's empty
'Check if the sub-folder is an ID or Name
If oBackup.FileName.StartsWith(oBackup.MonitorID & Path.DirectorySeparatorChar) Then
If Directory.Exists(sDir) Then
'Check if there's any sub-directories or files remaining
oDir = New DirectoryInfo(sDir)
If oDir.GetDirectories.Length = 0 And oDir.GetFiles.Length = 0 Then
'Folder is empty, delete the empty sub-folder
If Directory.Exists(sDir) Then DeleteDirectory(sDir)
End If
sDir = sBackupFolder & oBackup.MonitorID
ElseIf oBackup.FileName.StartsWith(oBackup.Name & Path.DirectorySeparatorChar) Then
sDir = sBackupFolder & oBackup.Name
Else
Exit Sub
End If
'Delete sub directory if it's empty
If Directory.Exists(sDir) Then
'Check if there's any sub-directories or files remaining
oDir = New DirectoryInfo(sDir)
If oDir.GetDirectories.Length = 0 And oDir.GetFiles.Length = 0 Then
'Folder is empty, delete the empty sub-folder
If Directory.Exists(sDir) Then DeleteDirectory(sDir)
End If
End If
End Sub