Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get a collection of sub folders from a parent folder
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00288982
Message ID:
00289003
Vues:
36
>>You should be able to get what you want from the ADIR() function.
>>
>>mnumdirs = adir(myarray, "c:\parent", "D")
>>
>>Is that what you were looking for?
>
>Somewhat, I am quite familiar with ADIR passing the D parameter, but it only gets one level, the child folders. Then I'd need to recursively call the function for each child, then again for each grandchild, etc. Can't be terribly difficult I just thought someone might have the recursion done so I could save a little time <g>. Why reinvent the wheel huh?

Hi William,

This might help
DEFINE CLASS Dir_Tree AS CUSTOM
  
  nargs = 0
  cdrive = ""
  DIMENSION a_dirs[1, 1]
  a_dirs[1, 1] = ""
  CurrDir = ""
  
  PROCEDURE Init
  
  LPARAMETER pcdrvltr
  
  LOCAL lcdriveltr
  This.nargs = PARAMETERS()
  lcdriveltr = pcdrvltr
  IF This.nargs = 0 OR EMPTY(pcdrvltr)
    This.cdrive = 'C:\'
  ELSE
    IF LEN(lcdriveltr) = 1
      lcdriveltr = lcdriveltr + ":"
    ENDIF
    This.cdrive = AddBS(lcdriveltr)
  ENDIF
  This.CurrDir = SYS(5) + CURDIR()
  RETURN
  
  PROCEDURE LoadTree
  
  LPARAMETER padirs, pcstartdir
  
  EXTERNAL ARRAY padirs
  LOCAL lni, lnlast, lnargs, a_dir
  lnargs = PARAMETERS()
  DIMENSION a_dir[1]
  IF lnargs = 1
    SET DEFAULT TO (This.cdrive)
    lnlast = ADIR(a_dir, "", 'D')
    IF LEN(This.cdrive) > 3
      * We're not starting at the root
      = ADEL(a_dir, 1)
      = ADEL(a_dir, 1)
      lnlast = lnlast - 2
      DIMENSION a_dir[lnlast, 5]
    ENDIF
    DIMENSION This.a_dirs[lnlast, 5]
    = ACOPY(a_dir, This.a_dirs)
    lni = 0
    DO WHILE lni < lnlast
      lni = lni + 1
      This.LoadTree(@a_dir, This.a_dirs[lni, 1])
      lnlast = ALEN(This.a_dirs, 1)
    ENDDO
    DIMENSION padirs[lnlast, 5]
    = ACOPY(This.a_dirs, padirs)
  ELSE
    SET DEFAULT TO (This.cdrive + pcstartdir)
    lnlast = ADIR(a_dir, "", 'D')
    IF lnlast > 2
      * Remove the first two elements
      * which contain "." and ".."
      * (the entry for the current directory 
      * and its parent)
      = ADEL(a_dir, 1)
      = ADEL(a_dir, 1)
      lnlast = lnlast - 2
      DIMENSION a_dir[lnlast, 5]
      FOR lni = 1 TO lnlast
        a_dir[lni, 1] = AddBS(pcstartdir) + a_dir[lni, 1]
      NEXT
      lnorglen = ALEN(This.a_dirs, 1)
      DIMENSION This.a_dirs[lnorglen + lnlast, 5]
      lnelenum = AELEMENT(This.a_dirs, lnorglen + 1, 1)
      = ACOPY(a_dir, This.a_dirs, 1, -1, lnelenum)
    ENDIF
  ENDIF
  SET DEFAULT TO (This.CurrDir)
  RETURN
ENDDEFINE
When you CREATEOBJECT(), passing the starting directory as a parameter. Then call the LoadTree() method with a dummy array. The results will be in the object's a_dir member, and will not include the starting directory.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform