delphi 文件,文件夹删除移动和拷贝


本文整理自网络,侵删。

 文件删除、移动和拷贝。
function WinErasefile(Owner: Integer; WichFiles: string; SendToRecycleBin, Confirm: Boolean): Boolean;
//用于将文件直接删除或移动到回收站
var
Struct : TSHFileOpStructA;
begin
FillChar(Struct, SizeOf(Struct), 0);
While pos(';', WichFiles)>0 do
WichFiles[pos(';', WichFiles)] := #0;
WichFiles := WichFiles + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Delete;
pFrom := PChar(WichFiles);
pTo := nil;
If not Confirm then fFlags := FOF_NOCONFIRMATION;
If SendToRecycleBin then fFLags := fFlags or FOF_ALLOWUNDO or FOF_FILESONLY
else fFlags := fFlags or 0 or FOF_FILESONLY;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;

function WinErasepath(Owner: Integer; WichFiles: string; SendToRecycleBin, Confirm: Boolean): Boolean;
//用于将目录直接删除或移动到回收站
var
Struct : TSHFileOpStructA;
begin
FillChar(Struct, SizeOf(Struct), 0);
While pos(';', WichFiles)>0 do
WichFiles[pos(';', WichFiles)] := #0;
WichFiles := WichFiles + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Delete;
pFrom := PChar(WichFiles);
pTo := nil;
If not Confirm then fFlags := FOF_NOCONFIRMATION;
If SendToRecycleBin then fFLags := fFlags or FOF_ALLOWUNDO
else fFlags := fFlags or 0 or FOF_FILESONLY;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;


function WinMovepath(Owner:Integer;FromFile, Tofile:string;ReNameOnCollision, Confirm:Boolean):Boolean;
//用于将目录进行移动
var
Struct : TSHFileOpStructA;
MultDest: Boolean;
begin
FillChar(Struct, SizeOf(Struct), 0);
MultDest := pos(';', ToFile)>0;
While pos(';', FromFile)>0 do
FromFile[pos(';', FromFile)] := #0;
While pos(';', ToFile)>0 do
ToFile[pos(';', ToFile)] := #0;
FromFile := FromFile + #0#0;
ToFile := ToFile + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Move;
pFrom := PChar(FromFile);
pTo := PChar(ToFile);
fFlags := FOF_ALLOWUNDO;
If MultDest then fFLags := fFlags or FOF_MULTIDESTFILES;
If ReNameOnCollision then fFLags := fFlags or FOF_RENameONCOLLISION;
If Confirm then fFLags := fFlags or FOF_NOCONFIRMATION;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;

function WinMovefile(Owner:Integer;FromFile, Tofile:string;ReNameOnCollision, Confirm:Boolean):Boolean;
//用于将文件进行移动
var
Struct : TSHFileOpStructA;
MultDest: Boolean;
begin
FillChar(Struct, SizeOf(Struct), 0);
MultDest := pos(';', ToFile)>0;
While pos(';', FromFile)>0 do
FromFile[pos(';', FromFile)] := #0;
While pos(';', ToFile)>0 do
ToFile[pos(';', ToFile)] := #0;
FromFile := FromFile + #0#0;
ToFile := ToFile + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Move;
pFrom := PChar(FromFile);
pTo := PChar(ToFile);
fFlags := FOF_ALLOWUNDO or FOF_FILESONLY;
If MultDest then fFLags := fFlags or FOF_MULTIDESTFILES;
If ReNameOnCollision then fFLags := fFlags or FOF_RENameONCOLLISION;
If Confirm then fFLags := fFlags or FOF_NOCONFIRMATION;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;

function WinCopypath(Owner: Integer; FromFile, Tofile: string;ReNameOnCollision, Confirm: Boolean): Boolean;
//拷贝目录
var
Struct : TSHFileOpStructA;
MultDest: Boolean;
begin
FillChar(Struct, SizeOf(Struct), 0); MultDest := pos(';', ToFile)>0;
While pos(';', FromFile)>0 do
FromFile[pos(';', FromFile)] := #0;
While pos(';', ToFile)>0 do
ToFile[pos(';', ToFile)] := #0;
FromFile := FromFile + #0#0;
ToFile := ToFile + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Copy;
pFrom := PChar(FromFile);
pTo := PChar(ToFile);
fFlags := FOF_ALLOWUNDO;
If MultDest then
fFLags := fFlags or FOF_MULTIDESTFILES;
If ReNameOnCollision then
fFLags := fFlags or FOF_RENameONCOLLISION;
If not Confirm then
begin
fFLags := fFlags or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
end;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;

function WinCopyfile(Owner: Integer; FromFile, Tofile: string;ReNameOnCollision, Confirm: Boolean): Boolean;
//拷贝文件
var
Struct : TSHFileOpStructA;
MultDest: Boolean;
begin
FillChar(Struct, SizeOf(Struct), 0); MultDest := pos(';', ToFile)>0;
While pos(';', FromFile)>0 do
FromFile[pos(';', FromFile)] := #0;
While pos(';', ToFile)>0 do
ToFile[pos(';', ToFile)] := #0;
FromFile := FromFile + #0#0;
ToFile := ToFile + #0#0;
with Struct do
begin
wnd := Owner;
wFunc := FO_Copy;
pFrom := PChar(FromFile);
pTo := PChar(ToFile);
fFlags := FOF_ALLOWUNDO or FOF_FILESONLY;
If MultDest then
fFLags := fFlags or FOF_MULTIDESTFILES;
If ReNameOnCollision then
fFLags := fFlags or FOF_RENameONCOLLISION;
If not Confirm then
begin
fFLags := fFlags or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
end;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
result := (SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted);
end;

相关阅读 >>

Delphi 如何判断字符串是否是有效email地址

Delphi fmx 安卓跳转到支付宝付款页面

Delphi中实现文件拷贝的三种方法

Delphi取得cxgrid 合计数

Delphi 注册表启动项管理代码

Delphi 声明指令 调用左右

Delphi屏蔽alt+tab键代码

Delphi 判断字符串是否为纯数字组合

Delphi通过代码实现模拟按键的函数

Delphi 获取标题栏高

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...