FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Leer carpetas y archivos que contiene? (SOLUCIONADO)
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Leer carpetas y archivos que contiene? (SOLUCIONADO)
Posted: Sun Dec 07, 2014 01:44 AM

Hola:

Amigos, necesito una funci贸n que me permita leer las carpetas y los archivos que contengan
cada una de las carpetas y crear un array para posteriormente crear un tree. ejemplo

|-----Carpeta 1
|-------- Archivo 1
|-------- Archivo 2
|-----Carpeta 2
|-------- Archivo 1

etc

Lo he intentado con la funci贸n DIRCTORY() pero no logro el objetivo.

Saludos

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Leer carpetas y archivos que contiene?
Posted: Sun Dec 07, 2014 08:18 AM
Armando,

Aqui lo tienes. Tarda un poco en cargar porque va a leer tu disco duro completo pero eso es parametrizable en el c贸digo variando el path de inicio.

Este tipo de c贸digo est谩 basado en la "recursividad". Si te fijas la funci贸n FillTree() se llama a ella misma :-)

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

聽 聽local oDlg, oTree
聽 聽
聽 聽DEFINE DIALOG oDlg SIZE 500, 340
聽 聽
聽 聽@ 0.5, 1 TREEVIEW oTree OF oDlg SIZE 100, 150
聽 聽
聽 聽ACTIVATE DIALOG oDlg CENTERED ;
聽 聽 聽 ON INIT FillTree( oTree, "C:\" ) 聽 聽 聽
聽 聽
return nil

function FillTree( oTree, cPath, oItem )

聽 聽local aInfo := Directory( cPath, "D" )
聽 聽local n, oNode

聽 聽for n = 1 to Len( aInfo )
聽 聽 聽 if ! aInfo[ n ][ 1 ] $ ".,.."
聽 聽 聽 聽 聽if oItem == nil
聽 聽 聽 聽 聽 聽 oNode = oTree:Add( aInfo[ n ][ 1 ] )
聽 聽 聽 聽 聽else 聽 
聽 聽 聽 聽 聽 聽 oNode = oItem:Add( aInfo[ n ][ 1 ] )
聽 聽 聽 聽 聽endif
聽 聽 聽 聽 聽if "D" $ aInfo[ n ][ 5 ]
聽 聽 聽 聽 聽 聽 FillTree( oTree, cPath + aInfo[ n ][ 1 ] + "\", oNode )
聽 聽 聽 聽 聽endif
聽 聽 聽 endif 聽 
聽 聽next

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Leer carpetas y archivos que contiene?
Posted: Sun Dec 07, 2014 05:46 PM

Maestro:

Excelente!, funciona de 100%, en realidad no necesito todo el DD, as铆 que lo de la
lentitud no es problema, como bien dices, es cuesti贸n del PATH.

Gracias Antonio

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion