DELPHI目录操作示例

//删除目录:

function DelDirectory(const Source:string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(source+#0);
pTo := #0#0;
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;


//复制目录:
function CopyDirectory(const Source, Dest: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := PChar(source+ #0 );
pTo := PChar(Dest+ #0 );
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR ;
end;
Result := (SHFileOperation(fo) = 0);
end;

//重新命名:
//RenDirectory('d:\wt2','d:\bcde');
function RenDirectory(const OldName,NewName:string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_RENAME;
pFrom := PChar(OldName+ #0 );
pTo := pchar(NewName+ #0 );
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;  

你可能感兴趣的:(Delphi)