title: Delete all files and folders recursively using Delphi
body: <p>I am trying to delete a folder and all of its sub-folders recursively but it is not working at all, so can someone please check the code and tell me what I am doing wrong here? </p>
  
  <p>I am running this code through D7 under Windows XP</p>
  
  <pre><code>if FindFirst (FolderPath + '\*', faAnyFile, f) = 0 then
        try             
           repeat
  
              if (f.Attr and faDirectory) &lt;&gt; 0 then
                begin
                      if (f.Name &lt;&gt; '.') and (f.Name &lt;&gt; '..') then
                        begin                            
                          RemoveDir(FolderPath +'\'+ f.Name);
                        end
                      else
                        begin
                          //Call function recursively...
                          ClearFolder(FolderPath +'\'+ f.Name, mask, recursive);
                        end;
                end;
  
           until (FindNext (f) &lt;&gt; 0);
        finally
          SysUtils.FindClose (f)
        end;
  end;
  </code></pre>