Exemple de fonction récursive de type BFF (Browse For Folder) | Sujet: Exemple de fonction récursive de type BFF (Browse For Folder) par Anonyme sur 18/6/2006 17:24:11
Je me suis essayé à la récursivité dans WinDev avec succès.
Voici un exemple permettant de trouver tous les répertoires fils d'un répertoire père. (utilisation directe de l'API bas niveau)
tabDirname est tableau dynamique de 0 string
sPath is string = "C:\mes projets\"
Bff_ReadDirs(sPath, tabDirname)
PROCEDURE Bff_ReadDirs(sPath is string, tabDirname)
FILETIME is structure
dwLowDateTime is int
dwHighDateTime is int
END
WIN32_FIND_DATA is structure
dwFileAttributes is int
ftCreationTime is FILETIME
ftLastAccessTime is FILETIME
ftLastWriteTime is FILETIME
nFileSizeHigh is int
nFileSizeLow is int
dwReserved0 is int
dwReserved1 is int
cFileName is string fixed on 260
cAlternateFileName is string fixed on 14
END
fd is WIN32_FIND_DATA
P, N is int
szPath is string ASCIIZ on 260 = sPath + "*"
hFind is int = API("KERNEL32", "FindFirstFileA", &szPath, &fd)
IF hFind <> -1 THEN
LOOP
IF BinaryAND(fd:dwFileAttributes, 16) THEN //Répertoire uniquement (16)
IF Asc(fd:cFileName) <> 46 THEN //Ni . ni ..
N = Max(ArrayInfo(tabDirname, tiDimension) + 1, 1)
Dimension(tabDirname, N)
P = Max(Position(fd:cFileName, Charact(0)) - 1, 0)
//On a trouvé un répertoire, on le mémorise
tabDirname[N] = sPath + Left(fd:cFileName, P) + "\"
Trace(N, tabDirname[N])
//On appel à nouveau la fonction pour trouver les autres
//Chaque appel récursif trouve sa place sur la pile (stack)
Bff_ReadDirs((tabDirname[N]), tabDirname)
END
END
TO DO WHILE API("KERNEL32","FindNextFileA", hFind, &fd)
API("KERNEL32", "FindClose", hFind)
END
Auteur Patrice Terrier Tel 04.76.98.16.73 pterrier@zapsolution.com www.zapsolution.com
|
|
Connexion
Menu
Chercher WDForge
Chercher Web
Partenaires
|