Bonjour,

Afin de supprimer certains fichiers, j'utilise depuis un bon bout de temps une fonction récursive qui fait correctement le travail. Cependant, voilà que le logiciel plante sur un ordinateur avec l'erreur Stack Overflow. Je doute que ce soit dû à une boucle qui tourne à l'infini (le logiciel fonctionne parfaitement sur les autres machines), donc je me penche plus pour une récursivité trop profonde qui fait déborder la pile. Voici ma procédure :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function slach(chemin : string) : string;
begin
 chemin := trim(chemin);
 if rightstr(chemin, 1) <> '\' then result := chemin + '\' else result := chemin;
end;
 
procedure ScanFiles(NomDossier : string ; subFolder : boolean);
var
 hFind : TSearchRec;
begin
 NomDossier := slach(NomDossier);
 if FindFirst(NomDossier + '*.*', FaAnyFile, hFind) = 0 then
 begin
  repeat
   if (hFind.Attr and faDirectory) <> faDirectory then
   begin
    Application.ProcessMessages;
    DeleteFile(NomDossier + hFind.Name);
   end else
   begin
    if (hFind.Name <> '.') and (hFind.Name <> '..') then
     if subFolder = True then ScanFiles((slach(NomDossier) + hFind.Name), subFolder);
   end;
  until FindNext(hFind) <> 0;
  FindClose(hFind);
  Application.ProcessMessages;
 end;
end;
Que faire pour empêcher cette erreur ?

Merci d'avance.