The following example illustrates the use of the
GetFolder method.
JScript
function ShowFolderList(folderspec)
{
var fso, f, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.SubFolders);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
VBScript
Function ShowFolderList(folderspec)
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
PowerBASIC
FUNCTION ShowFolderList (BYVAL strFolderSpec AS STRING) AS STRING
LOCAL fso AS IFileSystem
LOCAL f AS IFolder
LOCAL fc AS IFolderCollection
LOCAL s AS STRING
LOCAL hr AS LONG
LOCAL penum AS IEnumVARIANT
LOCAL v AS VARIANT
fso = NEWCOM ("Scripting.FileSystemObject")
f = fso.GetFolder(UCODE$(strFolderSpec))
fc = f.SubFolders
penum = fc.NewEnum_
DO
hr = penum.Next(1, v, BYVAL %NULL)
IF hr <> %S_OK THEN EXIT DO
f = v
s = s & ACODE$(f.Name) & $CRLF
LOOP
FUNCTION = s
END FUNCTION