Find Empty Folders

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have this script that is supposed to find empty folders and write them to
a text file. It works only partially. It actually accurately finds some
empty folders, and others it misses entirely. It also lists some but not all
folders that are empty of files but contain subfolders.

Basically I want to clean up my MP3 drive. WMP leave a lot of garbage
folders. SO The plan is to write to file any folder that is empty or better
yet any folder that doesn't contain an .mp3 or m3u file

Dim oShell, oFolder, oFolderItem, fso, selected, howbad, ColonPos
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Shell.Application")
On Error Resume Next
Set oFolder = oShell.BrowseForFolder(0, "Select where to search",&H0011 ,
ssfDRIVES)
Set oFolderItem = oFolder.Items.Item
Set selected=fso.GetFolder(oFolderItem.Path)
'
howbad = err.number
If howbad <> 0 Then
If howbad = 424 then
oFolder = Null
else
ColonPos = InStr(oFolder.Title, ":")
If ColonPos > 0 Then
selected = Mid(oFolder.Title, ColonPos - 1, 2) & "\"
End If
End If
End If
'
If IsNull(oFolder) Then MsgBox "No valid folder or drive
selected":WScript.Quit
'Set f=fso.CreateTextFile(fso.GetSpecialFolder(0)&"\desktop\Empties.txt")
Set f=fso.CreateTextFile("c:\Empties.txt")
f.WriteLine selected&" contains the following folders that are devoid of
files"
f.WriteLine " "
'
If selected.SubFolders.Count<>0 Then
WorkWithSubFolders selected
Else
If selected.files.Count=0 Then f.WriteLine selected
End If
'
Sub WorkWithSubFolders(selected)
Dim MoreFolders, TempFolder
If selected.files.Count=0 Then f.WriteLine selected
Set MoreFolders = selected.SubFolders
For Each TempFolder In MoreFolders
WorkWithSubFolders TempFolder
Next
End Sub
Set fso = Nothing
Set oShell = Nothing


.



Relevant Pages

  • Re: Folder Icons
    ... subfolders empty and some have files in them. ... The empty folders would retain ... the typical windows default yellow icon. ...
    (microsoft.public.vb.general.discussion)
  • Re: Windows XP cleaning with nLITE - additional clearout
    ... New C:\Program files still includes some empty folders that i ... Windows Media Player, WindowsNT\Pinball. ... Windows does not allow to cancel these folders directly. ...
    (alt.os.windows-xp)
  • Re: Searching for empty folders
    ... Windows® Troubleshooting http://www.winhelponline.com ... How Can I List All the Empty Folders on a Specified Drive? ... more subfolders and so on, and it and any of the subfolders can contain ...
    (microsoft.public.windowsxp.general)
  • Re: Windows XP cleaning with nLITE - additional clearout
    ... Media Player & other things (300Mb ... New C:\Program files still includes some empty folders that i consider ... Windows does not allow to cancel these folders directly. ...
    (alt.os.windows-xp)
  • Re: Get all folders
    ... > this code to recursively iterate the entire collection of folders. ... > Dim oFolder As Outlook.MAPIFolder ... > Dim colFolders As Outlook.Folders ...
    (microsoft.public.outlook.program_vba)