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

Re: Checking for empty directory by McKirahan

McKirahan
Mon Sep 12 08:51:50 CDT 2005

"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
>

Is a directory a file to you?

"dir" has directories but not files (in your example).

Also, shouldn't your list to check look like:

c:\dir\dir1\dir2\
c:\dir\dir1\dir2\dir3\
c:\dir\dir1\dir2\dir4\
c:\dir\dir1\dir2\dir5\

Do you want to drive it from a list or a single folder;
for example, c:\dir\ ?



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



Re: Checking for empty directory by McKirahan

McKirahan
Mon Sep 12 09:19:23 CDT 2005

"McKirahan" <News@McKirahan.com> wrote in message
news:ze2dnWPC5ebYELjeRVn-oQ@comcast.com...
> "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
> > >

Or, to simplify it:

Option Explicit
Const cFOL = "D:\Temp\"
Dim strFOL
Dim strMSG
strMSG = cFOL & " subfolders with no files: " & vbCrLf
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call GetSubFolders(cFOL)
Set objFSO = Nothing
Wscript.Echo strMSG

Sub GetSubFolders(FolderSpec)
For Each strFOL In objFSO.GetFolder(FolderSpec).Subfolders
If strFOL.Files.Count = 0 Then
strMSG = strMSG & vbCrLf & strFOL.Path
End If
Next
For Each strFOL in objFSO.GetFolder(FolderSpec).Subfolders
Call GetSubFolders(strFOL.Path)
Next
End Sub



Re: Checking for empty directory by gump33lt

gump33lt
Mon Sep 12 10:30:01 CDT 2005

Thanks for the feedback.

The directory that I would be checking should have no files or
subdirectories.

I will have a fixed path to the directories that I would want to check
so from your example:

c:\dir\dir1\dir2\
c:\dir\dir1\dir2\dir3\
c:\dir\dir1\dir2\dir4\
c:\dir\dir1\dir2\dir5\

the script should check c:\dir\dir1\dir2\<any directory>

and report if <any directory> has no files or subdirectories.

Larry


Re: Checking for empty directory by McKirahan

McKirahan
Mon Sep 12 10:36:04 CDT 2005

"gump33lt" <gump33lt@netscape.net> wrote in message
news:1126539001.184444.59880@f14g2000cwb.googlegroups.com...
> Thanks for the feedback.
>
> The directory that I would be checking should have no files or
> subdirectories.
>
> I will have a fixed path to the directories that I would want to check
> so from your example:
>
> c:\dir\dir1\dir2\
> c:\dir\dir1\dir2\dir3\
> c:\dir\dir1\dir2\dir4\
> c:\dir\dir1\dir2\dir5\
>
> the script should check c:\dir\dir1\dir2\<any directory>
>
> and report if <any directory> has no files or subdirectories.
>
> Larry
>

Will this work for you? Watch for word-wrap.

Option Explicit
Const cFOL = "c:\dir\dir1\dir2\"
Dim strFOL
Dim strMSG
strMSG = cFOL & " subfolders with no files: " & vbCrLf
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call GetSubFolders(cFOL)
Set objFSO = Nothing
Wscript.Echo strMSG

Sub GetSubFolders(FolderSpec)
For Each strFOL In objFSO.GetFolder(FolderSpec).Subfolders
If strFOL.SubFolders.Count = 0 _
And strFOL.Files.Count = 0 Then
strMSG = strMSG & vbCrLf & strFOL.Path
End If
Next
For Each strFOL in objFSO.GetFolder(FolderSpec).Subfolders
Call GetSubFolders(strFOL.Path)
Next
End Sub



Re: Checking for empty directory by gump33lt

gump33lt
Tue Sep 13 05:33:15 CDT 2005

That was perfect. Thanks very much for the help.

Larry