不好意思小弟是新手,不知是不是FindFirst还没释放所以删除不了
如果是那要怎办?
以下是测试代码procedure TForm1.Button1Click(Sender: TObject);
var
ph, str : string;
j : tsearchrec;
begin
ph := GetCurrentDir;
str := 'SK0001';
if FindFirst(ph + '\data\*' + Str + '*.Txt', faAnyFile, J) = 0 then
repeat
if faAnyFile > 0 then
DeleteFile(ph + '\' + 'dada\' + J.Name);
until FindNext(J) <> 0 ;
FindClose(J);
end;
end.
如果是那要怎办?
以下是测试代码procedure TForm1.Button1Click(Sender: TObject);
var
ph, str : string;
j : tsearchrec;
begin
ph := GetCurrentDir;
str := 'SK0001';
if FindFirst(ph + '\data\*' + Str + '*.Txt', faAnyFile, J) = 0 then
repeat
if faAnyFile > 0 then
DeleteFile(ph + '\' + 'dada\' + J.Name);
until FindNext(J) <> 0 ;
FindClose(J);
end;
end.
var
ph, str : string;
j : tsearchrec;
begin
ph := GetCurrentDir;
str := 'SK0001';
if FindFirst(ph + '\data\*' + str +'*.Txt', faAnyFile, J) = 0 then
repeat
//if faAnyFile > 0 then //faAnyFile是一个常量(71),这样判断无任何意义。
DeleteFile(ph + '\' + 'dada\' + J.Name); //上面是data,这个是dada,路径不一样怎么删。
until FindNext(J) <> 0 ;
FindClose(J);
end;
var
ph, str : string;
j : tsearchrec;
begin
ph := 'D:\tmp\';//路径自己调
if FindFirst(ph+ '*.txt', faAnyFile, J) = 0 then
repeat
if (faAnyFile > 0) and (Pos(J.Name)>0) then
DeleteFile(ph + J.Name);
until FindNext(J) <> 0 ;
FindClose(J);
end;
不过还是非常多谢两位,
尤其 Oraclers 比我早发现问题,
小弟要来结帖时才发现已经有答案了
不过您的建议也相当有效,多谢。