Re: Delphi duplicate file with slight change in the document name

Posted by webmaster Guido on May 01, 2001 at 23:53:47:

In Reply to: Delphi duplicate file with slight change in the document posted by Peter Cook on May 01, 2001 at 18:32:25:

: How would one go about creating a cook.txt in the folder c:\PETER, and then duplicating this very same document 10 times but with a slight change in the name of the document (otherwise it would obviously be overwriting the cook.txt 10 times). For example, c:\PETER\cook.txt would be created, then perhaps c:\PETER\cook1.txt, then cook2.txt and so fourth. I was thinking some kind of a loop, but I can't figure out the correct syntax.
-------

Have a look at the procedure below, with as its parameters:
- TheText: a string that contains the text that you want to save on disk
- Dir: the directory where you want to save the text-files, e.g. 'C:\PETER'
- BaseName: first part of the filename, e.g. 'COOK'
- Times: how many copies must be saved?

procedure MultiNameSave(TheText, Dir, BaseName: string; Times: integer);
var
  i: integer;
  TheFileName: string;
begin
  for i := 1 to Times do begin
    TheFileName := Dir + BaseName + IntToStr(i) + '.txt';
    // Any code of your choice that saves TheText under the name TheFileName:
    // ...
    // ...
  end;
end;



Related Articles and Replies: