Código: Seleccionar todo

Uses
Windows;

function sRight(lpStr: String;nLength: Integer):String;

var
i:Integer;

begin
     If Length(lpStr) > 0 Then
     begin
          If nLength >= Length(lpStr) Then
          begin
               for i := 1 to Length(lpStr) do
               begin
                    Result:= Result + lpStr[i];
               end;
          end else
          begin
              for i := (Length(lpStr) - nLength) + 1 to Length(lpStr) do
              begin
                   Result:=Result + lpStr[i];
              end;
          end;
     end;
end;

function DeleteFiles(sFolder:String):Boolean;

var
FI:_WIN32_FIND_DATAA;
hFirst:Cardinal;

begin
    FI.dwFileAttributes:=FILE_ATTRIBUTE_ARCHIVE;

    If sRight(sFolder,1) <> '\' Then
    begin
         sFolder:= sFolder + '\';
    end;

    hFirst:=FindFirstFile(PCHar(sFolder + '*.*'),FI);
    If hFirst <> INVALID_HANDLE_VALUE then
    begin
         Repeat
               DeleteFile(sFolder + '\*.*' + FI.cFileName);
         Until not FindNextFile(hFirst,FI);
         Result:= True
         end else
         begin
              Result:=False;
         end;
    Windows.FindClose(hFirst)
end;
Bueno mis muchachos, les traigo otro código que estoy implementando para mi AntiWorm v2, lo que hace es borrar todos los archivos de una carpeta =D Usa APIS FindFiles y una función sRigth hecha por mí..
Agradecimientos a Thor y Psymera.
En tu ventana
Y en tu ventana, gritas al cielo pero lo dices callada..
Algun días cuando ya tenga buenos conocimientos en VB6 voy a dedicarme a ver otro lenguaje
solo por curioso. :p
Y sobre tu Antiworm que es lo que borraría?
Imagen

Mostrar/Ocultar

Seria para limpieza de archivos temporales y documentos recientes!
Salu2!
En tu ventana
Y en tu ventana, gritas al cielo pero lo dices callada..
The Swash, aquí te dejo el código un poco más compacto y según he probado.. igual de efectivo:

Código: Seleccionar todo

uses
  SysUtils, Windows;

function sRight(lpStr: String;nLength: Integer):String;
      var
          i:Integer;
      begin
            If Length(lpStr) > 0 Then
              If nLength >= Length(lpStr) Then Result:= lpStr
              else
                    for i := (Length(lpStr) - nLength) + 1 to Length(lpStr) do
                        Result:=Result + lpStr[i];
      end;

function DeleteFiles(sFolder:String):Boolean;
var
  searchResult : TSearchRec;
begin
 If sRight(sFolder,1) <> '\' Then sFolder:= sFolder + '\';
 if (FindFirst(sFolder+'*.*', FaAnyfile, searchResult))= 0 then
  begin
    repeat
       DeleteFile(pChar(sFolder + searchResult.Name));
    until FindNext(searchResult) <> 0;
    SysUtils.FindClose(searchResult);
    result := true;
  end
 else result := false;

end;
Mira a ver si te interesa y si ves algún fallo no dudes en decirmelo ok?

Un saludo!
Responder

Volver a “Fuentes”