A
ANDREWWUYOU
Unregistered / Unconfirmed
GUEST, unregistred user!
怎么删除不了这个文件===ABC.TXT
function GetFileLocation(const Filename: string; StartAt: string):
string;
procedure Traverse(const AFolder: string);
var SearchRec: TSearchRec;
begin
if Result <> '' then Exit;
if FindFirst(AFolder+'*', faAnyFile, SearchRec) = 0 then
try
repeat
if (SearchRec.Name[1] <> '.') then
if SearchRec.Attr AND faDirectory > 0 then
Traverse(AFolder + SearchRec.Name + '/')
else
if AnsiCompareText(SearchRec.Name, Filename) = 0 then
Result := AFolder + SearchRec.Name;
until (FindNext(SearchRec) <> 0) or (Result <> '');
finally
FindClose(SearchRec);
end;
end;
begin
Result := '';
if StartAt[Length(StartAt)] <> '/' then StartAt := StartAt + '/';
Traverse(StartAt);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ExtractFileName(GetFileLocation(ABC.TXT','c:/'))= 'ABC.TXT' then
if DeleteFile( 'connect.ini') then
showmessage('has deleted!' ) else
showmessage('no deleted!');
END:
function GetFileLocation(const Filename: string; StartAt: string):
string;
procedure Traverse(const AFolder: string);
var SearchRec: TSearchRec;
begin
if Result <> '' then Exit;
if FindFirst(AFolder+'*', faAnyFile, SearchRec) = 0 then
try
repeat
if (SearchRec.Name[1] <> '.') then
if SearchRec.Attr AND faDirectory > 0 then
Traverse(AFolder + SearchRec.Name + '/')
else
if AnsiCompareText(SearchRec.Name, Filename) = 0 then
Result := AFolder + SearchRec.Name;
until (FindNext(SearchRec) <> 0) or (Result <> '');
finally
FindClose(SearchRec);
end;
end;
begin
Result := '';
if StartAt[Length(StartAt)] <> '/' then StartAt := StartAt + '/';
Traverse(StartAt);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ExtractFileName(GetFileLocation(ABC.TXT','c:/'))= 'ABC.TXT' then
if DeleteFile( 'connect.ini') then
showmessage('has deleted!' ) else
showmessage('no deleted!');
END: