Author Topic: IFolder.SubFolders Property  (Read 2708 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2524
  • User-Rate: +209/-0
  • Gender: Male
IFolder.SubFolders Property
« on: July 14, 2008, 12:30:03 AM »

The following code illustrates the use of the SubFolders property:

JScript

Code: [Select]
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

Code: [Select]
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

Code: [Select]
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