Re: Checking for empty directory by McKirahan
McKirahan
Mon Sep 12 09:14:29 CDT 2005
"McKirahan" <News@McKirahan.com> wrote in message
news:eZednQWERb1rGrjeRVn-sw@comcast.com...
> "gump33lt" <gump33lt@netscape.net> wrote in message
> news:1126530405.421671.122380@g14g2000cwa.googlegroups.com...
> > I've done a lot of unix shell scripting and awk/sed work but I'm new to
> > the vbscript world.
> >
> > I need to create a script that checks a list of directories and reports
> > which contain no files.
> >
> > In the following example, dir3, dir4 and dir5 are under dir2. The
> > script should report if any of dir3,4, or 5 have no files in them.
> >
> > c:\dir\dir1\dir2
> > dir3
> > dir4
> > dir5
> >
> > TIA.
> >
> > Larry
> >
Will this help? Watch for word-wrap.
Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "nofiles.vbs"
Const cFOL = "c:\dir\"
'*
'* Declare Variables
'*
Dim arrFOL()
ReDim arrFOL(1,0)
Dim intFOL
intFOL = 0
Dim strFOL
Dim strMSG
strMSG = cFOL & " subfolders with no files: " & vbCrLf
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*
'* GetSubFolders()
'*
Call GetSubFolders(cFOL)
'*
'* Destroy Objects
'*
Set objFSO = Nothing
'*
'* Display Results
'*
For intFOL = 1 To UBound(arrFOL,2)
If arrFOL(1,intFOL) = 0 Then
strMSG = strMSG & vbCrLf & arrFOL(0,intFOL)
End If
Next
Wscript.Echo strMSG
Sub GetSubFolders(FolderSpec)
For Each strFOL In objFSO.GetFolder(FolderSpec).Subfolders
intFOL = intFOL + 1
ReDim Preserve arrFOL(1,intFOL)
arrFOL(0,intFOL) = strFOL.Path
arrFOL(1,intFOL) = strFOL.Files.Count
Next
For Each strFOL in objFSO.GetFolder(FolderSpec).Subfolders
Call GetSubFolders(strFOL.Path)
Next
End Sub