文件复制

  • A+
所属分类:[开发技巧]

方法一:implementationuses ShellAPI;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

var

FOS :TSHFileOpStruct;

begin

with FOS do

begin

Wnd := Self.Handle;

wFunc := FO_COPY;

pFrom := 'c:\idapi\*.*';

pTo := 'c:\test';

fFlags := FOF_NoConfirmMkDir;

end;

SHFileOperation(FOS);

end

方法二:

implementationuses ShellAPI;

{$R *.DFM

}procedure TForm1.Button1Click(Sender: TObject);

var

FOS :TSHFileOpStruct;

begin

with FOS do

begin

Wnd := Self.Handle;

wFunc := FO_COPY;

pFrom :='c:\newjlzf\data\zjjlb*.*';

pTo :='c:\xy';

fAnyOperationsAborted:=true;

fFlags :=FOF_CONFIRMMOUSE ;//FOF_FILESONLY ;// FOF_SILENT ;//FOF_NoConfirmMkDir;

end;

SHFileOperation

方法三:

procedure XCopyDir(SourceDir, TargetDir: string);

var DirInfo: TSearchRec; DosError: Integer;

begin

DosError := FindFirst(SourceDir+'\*.*', FaAnyfile, DirInfo);

if not DirectoryExists(TargetDir) then

ForceDirectories(TargetDir);

while DosError=0 do

begin

if ((DirInfo.Attr and FaDirectory)=faDirectory) and (DirInfo.Name<>'.') and (DirInfo.Name<>'..') then

XCopyDir(SourceDir + '\' + DirInfo.Name, TargetDir + '\' + DirInfo.Name);

{$IF DEFINED(WIN32) AND DECLARED(UsingVCL)}

if ((DirInfo.Attr and FaDirectory)<>FaDirectory) and ((DirInfo.Attr and FaVolumeID)<>FaVolumeID) {$ELSE}

if ((DirInfo.Attr and FaDirectory)<>FaDirectory) {$IFEND} then

CopyFile(PChar(SourceDir + '\' + DirInfo.Name), PChar(TargetDir + '\' + DirInfo.Name), false);

DosError := FindNext(DirInfo);

end;

SysUtils.FindClose(DirInfo);

end;

历史上的今天
十月
10
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: