Wednesday, November 23, 2016

Empty Folder Del

on error resume next

Dim wshShell, objFSO, ProgramFiles

Set wshShell =CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
ProgramFiles=wshShell.ExpandEnvironmentStrings("%ProgramFiles%")

If FolderEmpty(ProgramFiles & "\MATLAB") Then
objFSO.DeleteFolder ProgramFiles & "\MATLAB"
End If



Function FolderEmpty(strFolder)
Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strFolder) Then
    Set objFolder = objFSO.GetFolder(strFolder)
 
    If objFolder.Files.Count = 0 And objFolder.SubFolders.Count = 0 Then
        FolderEmpty=True
    Else
        FolderEmpty=False

    End If
End If

Set objFSO = Nothing
End Function


Set wshShell = Nothing
Set objFSO = Nothing
WScript.Quit

No comments:

Post a Comment