• Welcome to Jose's Read Only Forum 2023.
 

IFolder.IsRootFolder Property

Started by José Roca, July 14, 2008, 12:48:09 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following code illustrates the use of the IsRootFolder property:

JScript


function DisplayLevelDepth(pathspec)
{
   var fso, f, n, s = "";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFolder(pathspec);
   n = 0;
   if (f.IsRootFolder)
      s = "The specified folder is the root folder."
   else
   {
      do
      {
         f = f.ParentFolder;
         n++;
      }
      while (!f.IsRootFolder)
      s = "The specified folder is nested " + n + " levels deep."
   }
   return(s);
}


VBScript


Function DisplayLevelDepth(pathspec)
   Dim fso, f, n
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(pathspec)
   If f.IsRootFolder Then
      DisplayLevelDepth = "The specified folder is the root folder."
   Else
      Do Until f.IsRootFolder
         Set f = f.ParentFolder
         n = n + 1
      Loop
      DisplayLevelDepth = "The specified folder is nested " & n & " levels deep."
   End If
End Function


PowerBASIC


FUNCTION DisplayLevelDepth (BYVAL strPathSpec AS STRING) AS STRING

   LOCAL fso AS IFileSystem
   LOCAL f AS IFile
   LOCAL n AS LONG

   fso = NEWCOM ("Scripting.FileSystemObject")
   f = fso.GetFolder(UCODE$(strPathSpec))
   IF f.IsRootFolder THEN
      FUNCTION = "The specified folder is the root folder."
   ELSE
      DO
         IF f.IsRootFolder THEN EXIT DO
         f = f.ParentFolder
         n = n + 1
      LOOP
      FUNCTION = "The specified folder is nested " & FORMAT$(n) & " levels deep."
   END IF

END FUNCTION