Delphi 如何将多个文件复制到一个


本文整理自网络,侵删。

 
Answer 1
procedure TForm1.Button1Click(Sender: TObject);
var
  Stream1, Stream2: TFileStream;
begin
  Stream1 := TFileStream.Create('c:\file4', fmCreate or fmShareExclusive);
  try
    { first file }
    Stream2 := TFileStream.Create('c:\file1', fmOpenRead or fmShareDenyNone);
    try
      Stream1.CopyFrom(Stream2, Stream2.Size);
    finally
      Stream2.Free;
    end;
    { next file }
    Stream2 := TFileStream.Create('c:\file2', fmOpenRead or fmShareDenyNone);
    try
      Stream1.CopyFrom(Stream2, Stream2.Size);
    finally
      Stream2.Free;
    end;
    { and so on }
  finally
    Stream1.Free;
  end;
end;
Tip by Finn Tolderlund

Answer 2
function AppendFiles(Files: TStrings; const DestFile: string): integer;
var
  srcFS, destFS: TFileStream;
  i: integer;
  F: string;
begin
  result := 0;
  if (Files.Count > 0) and (DestFile <> '') then
  begin
    destFS := TFileStream.Create(DestFile, fmCreate or fmShareExclusive);
    try
      i := 0;
      while i < Files.Count do
      begin
        F := Files(i);
        Inc(i);
        if (CompareText(F, DestFile) <> 0) and (F <> '') then
        begin
          srcFS := TFileStream.Create(F, fmOpenRead or fmShareDenyWrite);
          try
            if destFS.CopyFrom(srcFS, 0) = srcFS.Size then
              Inc(result);
          finally
            srcFS.Free;
          end;
        end
        else
        begin
          { error }
        end;
      end;
    finally
      destFS.Free;
    end;
  end;
end;

相关阅读 >>

Delphi cookie获取及使用

Delphi xe8在firemonkey tlistbox中显示图像

Delphi 刷新桌面函数

Delphi 文件/流的加密解密方法

Delphi listview高速添加数据

Delphi 三层架构简单例子(经测试成功)

Delphi xe5 for android ttabcontrol 控件

Delphi 实现卸载windows应用程序(类似360软件管家-卸载程序)

Delphi trect的宽和高

windows关机函数exitwindowsex使用大全(适用windows所有操作平台)

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



打赏

取消

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

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

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

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

评论

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