我想删除c:/good/123.exe这个文件,应该怎么做?(0分)

  • 主题发起人 主题发起人 nakoka
  • 开始时间 开始时间
N

nakoka

Unregistered / Unconfirmed
GUEST, unregistred user!
顺便问问,我要把c:/good/下面的所有文件删除应该怎么做?
 
DeleteFile('c:/good/bad.exe');
谢谢卷起千堆雪大哥!
愿上帝保佑您!
 
^_^

function DoRemoveDir(sDirName:String):Boolean;
var
hFindFile:Cardinal;
tfile:String;
sCurDir:String;
bEmptyDir:Boolean;
FindFileData:WIN32_FIND_DATA;
begin
bEmptyDir:=True;
sCurDir:=GetCurrentDir;
SetLength(sCurDir,Length(sCurDir));
ChDir(sDirName);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile<>INVALID_HANDLE_VALUE then
begin
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
begin
bEmptyDir:=bEmptyDir and True;
Continue;
end;
bEmptyDir:=False;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
if sDirName[Length(sDirName)]<>'/' then
DoRemoveDir(sDirName+'/'+tfile)
else
DoRemoveDir(sDirName+tfile);
if not RemoveDirectory(PChar(tfile)) then
result:=false
else
result:=true;
end
else
begin
if not DeleteFile(PChar(tfile)) then
result:=false
else
result:=true;
end;
until FindNextFile(hFindFile,FindFileData)=false;
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
if bEmptyDir then
begin
ChDir('..');
RemoveDirectory(PChar(sDirName));
end;
ChDir(sCurDir);
result:=true;
end;

function DeleteDir(sDirName:String):Boolean;
begin
if Length(sDirName)<=0 then
exit;
Result:=DoRemoveDir(sDirName) and RemoveDir(sDirName);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if DeleteDir('c:/good') then
ShowMessage('ok');
end;
 
DeleteFile(PChar('c:/good/bad.exe'));
=======================================
//==========删除一个文件夹内的所有文件=============================
procedure TMainFm.delitem(s:string;Sender: TObject);
var OpStruc: TSHFileOpStruct;
frombuf, tobuf: Array [0..128] of Char;
begin
FillChar( frombuf, Sizeof(frombuf), 0 );
FillChar( tobuf, Sizeof(tobuf), 0 );
StrPCopy( frombuf, s );
With OpStruc DO Begin
Wnd:= Handle;
wFunc:= FO_DELETE;
pFrom:= @frombuf;
pTo:=@tobuf;
fFlags:= FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:= False;
hNameMappings:= Nil;
lpszProgressTitle:= Nil;
end;
ShFileOperation( OpStruc );
end;
例:delitem('c:/test',Sender);
 
接受答案了.
 
后退
顶部