Re: Count of TXT files in a folder by Paul
Paul
Wed Mar 05 17:37:16 CST 2008
"XP" <XP@discussions.microsoft.com> wrote in message
news:27D78CDA-1F89-4F0B-AC3C-907A0054B3F0@microsoft.com...
> In an HTA, using VBScript, I need to get a count of only files
> having a TXT
> file extension in a specific folder.
>
> Can someone please post generic example code to do this?
>
> Thanks much in advance.
The scripting help file SCRIPT56.CHM might help you.
Searching the index for the word files should give you two choices.
Both bring you to sample VBScript like:
[VBScript]Function ShowFileList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFileList = s
End Function
The two lines within the For ... Next loop were designed to list the
file names within HTML. By replacing those lines with the following,
you could count those files with the .txt extension.
If Right(lCase(fl.name), 4) = ".txt" Then
iCount = iCount + 1
Emd If
The function could return the value of iCount as the function's value.
-Paul Randall