随
随风而逝
Unregistered / Unconfirmed
GUEST, unregistred user!
/删除文件及文件夹函数
//deleteFile(form1.DirectoryEdit2.Text+'/' , '*', ' ',strtoint(form1.RxSpinEdit2.text));
//form1.directoryedit2.text 是上级文件夹名称 c:/test/
//* 表示删除子目录
// strtoint(form1.RxSpinEdit2.text)目录比较 我的目录为 2007-12-8-15-47这种格式
procedure deleteFile(strd:string ; ex:string ; bex:string ; count :integer);
var sr :TSearchRec;
name :string;
filetime :Tdatetime;
begin
if FindFirst(strd+ex,faAnyFile,sr)=0 then
begin
repeat
begin
name:=copy(sr.Name,length(bex)+1,length(sr.Name) - length(ex+bex)+1);
showmessage(name);
try
filetime:=strtodatetime(name)
except
continue
end;
if daysbetween(now(),filetime) >= count then
begin
if ex<>'*' then
winexec(pchar('cmd.exe /c del '+strd+sr.name+' /q'),sw_hide) //文件
else
winexec(pchar('cmd.exe /c rd '+strd+sr.name+' /q/s'),sw_hide); //目录
form1.Memo1.Lines.Add(datetimetostr(now())+' '+'删除文件'+strd+sr.Name);
end;
end;
until FindNext(sr)<>0
end;
findclose(sr);
end;
//deleteFile(form1.DirectoryEdit2.Text+'/' , '*', ' ',strtoint(form1.RxSpinEdit2.text));
//form1.directoryedit2.text 是上级文件夹名称 c:/test/
//* 表示删除子目录
// strtoint(form1.RxSpinEdit2.text)目录比较 我的目录为 2007-12-8-15-47这种格式
procedure deleteFile(strd:string ; ex:string ; bex:string ; count :integer);
var sr :TSearchRec;
name :string;
filetime :Tdatetime;
begin
if FindFirst(strd+ex,faAnyFile,sr)=0 then
begin
repeat
begin
name:=copy(sr.Name,length(bex)+1,length(sr.Name) - length(ex+bex)+1);
showmessage(name);
try
filetime:=strtodatetime(name)
except
continue
end;
if daysbetween(now(),filetime) >= count then
begin
if ex<>'*' then
winexec(pchar('cmd.exe /c del '+strd+sr.name+' /q'),sw_hide) //文件
else
winexec(pchar('cmd.exe /c rd '+strd+sr.name+' /q/s'),sw_hide); //目录
form1.Memo1.Lines.Add(datetimetostr(now())+' '+'删除文件'+strd+sr.Name);
end;
end;
until FindNext(sr)<>0
end;
findclose(sr);
end;