Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Hard drive directory parser needed
Message
 
À
02/02/2001 16:04:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00471992
Message ID:
00472176
Vues:
29
>Hi Folks,
>
>I need a VFP routine/class/code that will parse or crawl through a directory structure and return all the subdirectory names within it. Returning the file names within each subdirectory would be ok too! The subdirectories may go to any number of levels.
>
>Thanks
>Dean

Dean: See this "pure" VFP function
*-----------------------------------------------------------------
* FUNCTION ASubDir(taArray, tcRoot)
*-----------------------------------------------------------------
* Return in an Array passed through reference all the all their 
* subdirectory and file names of the directory "tcRoot"
* The names are of the form: [Drive]:\[Directory]\[File Name]
*
* RETURN: The number of archives in the Array. If it did not find 
*         any file or the directory "tcRoot" does not exist, 
*         returns 0 (zero)´
* AUTHOR: LMG  
*
* EXAMPLE OF USE: 
*    DIMENSION laMiArray[1]
*    lnC = ASubDir(@laMiArray, "C:\Program files")
*    FOR lnI = 1 to lnC
*       ? laMiArray[lnI]
*    ENDFOR
*-----------------------------------------------------------------
FUNCTION ASubDir(taArray, tcRoot)
  IF EMPTY(tcRoot)
    tcRoot = SYS(5) + CURDIR()
  ENDIF
  DIMENSION taArray[1]
  =ARecur(@taArray, tcRoot)
  IF ALEN(taArray) > 1
    DIMENSION taArray[ALEN(taArray) - 1]
    RETURN ALEN(taArray)
  ELSE
    RETURN 0	
  ENDIF
ENDFUNC
*-----------------------------------------------------------------
* FUNCTION ARecur(taArray, tcRoot)
*-----------------------------------------------------------------
* Recursive function called by ASubDir()
*-----------------------------------------------------------------
FUNCTION ARecur(taArray, tcRoot)
  PRIVATE lnI, lnCant, laAux
  tcRoot = ADDBS(tcRoot)
  lnCant = ADIR(laAux, tcRoot+"*.*", "D")
  FOR lnI = 1 TO lnCant
    IF "D" $ laAux[lnI, 5]
      IF laAux[lnI, 1] == "." OR laAux[lnI, 1] == ".."
        LOOP
      ELSE
        lcSubDir = tcRoot + laAux[lnI, 1]
        =ARecur(@taArray, lcSubDir)
        LOOP
      ENDIF
    ENDIF
    taArray[ALEN(taArray)] = tcRoot + laAux[lnI, 1]
    DIMENSION taArray[ALEN(taArray) + 1]
  ENDFOR
  RETURN
ENDFUNC
*-----------------------------------------------------------------
Luis María Guayán
Tucumán, Argentina
________________________________
SysOp de www.PortalFox.com
Nada corre como un zorro
________________________________
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform