Apagar arquivos
Olá amigos estou precisando apagar arquivos que fica dentro de uma determinada pasta, gostaria de seleciona-los pela data de modificação.
Exemplo : apagar todos as arquivos que a data de modificação seja menos que 10 dias.
Nesta pasta existem muitos arquivos e eu não consigo ler um por um, com este comando irá apagar pela data de modificação.
Muito obrigado.
Marcelo
Curtidas 0
Respostas
Marco Salles
17/08/2010
Vc pode pegar a idéia
ha outras maneiras , bem como outros métodos
Aqui eu não deleto , apenas mostro
var i:integer; begin with FileListBox1 do begin Directory:='C:\zPodeApagar'; //Aqui seu Diretorio for I := 0 to pred(Count) do if FileDateToDateTime(FileAge(Items.Strings[i])) >= (Date - 15) then //Aqio a condição showmessage(Items.Strings[i]); end; end;
GOSTEI 0
Eriley Barbosa
17/08/2010
function GetFileDate(Arquivo: String): String;
var FHandle: integer;
begin
FHandle := FileOpen(Arquivo, 0);
try
Result := DateToStr(FileDateToDateTime(FileGetDate(FHandle)));
finally
FileClose(FHandle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec : TSearchRec;
Data: string;
begin
try
FindFirst('C:\Teste\*.exe', faAnyFile, SearchRec); repeat
if SearchRec.name <> '' then
Data := GetFileDate('C:\Teste\' + SearchRec.name);
if Data <> '' then
if Data = DateToStr(Now - 10) then
DeleteFile('C:\Teste\' + SearchRec.name);
until FindNext(SearchRec) <> 0;
finally
FindClose(SearchRec);
end;
end; Atenciosamente Eriley
var FHandle: integer;
begin
FHandle := FileOpen(Arquivo, 0);
try
Result := DateToStr(FileDateToDateTime(FileGetDate(FHandle)));
finally
FileClose(FHandle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec : TSearchRec;
Data: string;
begin
try
FindFirst('C:\Teste\*.exe', faAnyFile, SearchRec); repeat
if SearchRec.name <> '' then
Data := GetFileDate('C:\Teste\' + SearchRec.name);
if Data <> '' then
if Data = DateToStr(Now - 10) then
DeleteFile('C:\Teste\' + SearchRec.name);
until FindNext(SearchRec) <> 0;
finally
FindClose(SearchRec);
end;
end; Atenciosamente Eriley
GOSTEI 0
Marco Salles
17/08/2010
A classe TSearchRec atende muitissimo bem
Vale resaltar que no Delphi2010 a Unidade IOutils.pas ... Similar ao NomeSpace System.IO presente no .NET
Possui Classes que facilita o Trabalho com Arquivos e Diretórios
T Directory
TPath
TFile
o que falita neste trabalho... sem dizer de possivel warning do compilador que podera acusar Decrepted
GOSTEI 0