删除目录:
uses ShellApi;
var
fo: TSHFILEOPSTRUCT;
begin
fo.Wnd := Application.Handle;
fo.wFunc := FO_DELETE;
fo.pFrom := PChar(Dir+#0#0);
fo.pTo := PChar(ExtractFilePath(ParamStr(0)));
fo.fFlags := FOF_NOCONFIRMATION;
ShFileOperation(fo);
end;
拷贝目录
var
fo: TSHFILEOPSTRUCT;
begin
fo.Wnd := Application.Handle;
fo.wFunc := FO_Copy;
fo.pFrom := PChar(Dir+#0#0);
fo.pTo := PChar(ExtractFilePath(ParamStr(0)));
fo.fFlags := FOF_NOCONFIRMATION;
ShFileOperation(fo);
end;
拷贝文件
var
FSearchRec,DSearchRec : TSearchRec;
FindResult : integer;
function IsDirNotation(ADirName : string):Boolean;
begin
result := (ADirName = '.') or (ADirName='..');
end;
begin
APath := GetDirectoryName(APath);
FindResult := FindFirst(APath+'*.*',SysUtils.faAnyFile+SysUtils.faHidden+SysUtils.faSysFile+SysUtils.faReadOnly,FSearchRec);
try
while FindResult = 0 do
begin
CopyFile(PChar(APath+FSearchRec.Name),PChar(ExtractFilePath(ParamStr(0))+FSearchRec.Name),false);
FindResult := FindNext(FSearchRec);
end;
FindResult := FindFirst(APath+'*.*',faDirectory,DSearchRec);
while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not (IsDirNotation(DSearchRec.Name)) then
copyDir(APath+DSearchRec.Name);
FindResult := FindNext(DSearchRec);
end;
finally
FindClose(FSearchRec);
end;