title: CopyFile - save without overwriting existing file
body: <p>What am I doing:</p>
  
  <ul>
  <li>User clicks a button, a <code>FileUpload</code> component (dialog) fires up and he can
  browse for and load a file from his PC.</li>
  <li>When he clicks ok the file gets saved to the disk, in a specific
  location.</li>
  <li>Prior to saving I'm renaming (or rather, saving with a specific name) his file using some string that contain
  data I previously pulled from some DB fields.</li>
  </ul>
  
  <p>Hence, regardless of the name the file has when the user loads it, it gets saved to the disk with his <code>Firstname</code> and <code>LastName</code>, which I get from some string variables.</p>
  
  <p><code>UniMainModule.foldername</code> = contains the path to the folder where the file gets saved.</p>
  
  <p><code>UniMainModule.FirstName</code> = contains the user's FirstName</p>
  
  <p><code>UniMainModule.LastName</code> = contains the user's LastName</p>
  
  <p>Thus, the file gets saved as <code>FirstName_LastName.pdf</code> on the disk at location provided by <code>foldername</code> string.</p>
  
  <p>This is the code I'm using:</p>
  
  <pre><code>procedure TsomeForm.UniFileUpload1Completed(Sender: TObject; AStream: TFileStream);
  var
    DestName : string;
    DestFolder : string;
  begin
     DestFolder:=UniServerModule.StartPath+'files\'+UniMainModule.foldername+'\';
     DestName:=DestFolder+UniMainModule.FirstName+'_'+UniMainModule.LastName+'.pdf';
     CopyFile(PChar(AStream.FileName), PChar(DestName), False);
     ModalResult:= mrOk;
  end;
  </code></pre>
  
  <p>As I understand it, after reading a bit about <code>CopyFile</code> on <code>msdn</code> passing <code>False</code> means that it should and will overwrite the existing file.</p>
  
  <p>If the file isn't already present with that name in that location, it's fine, it gets saved.</p>
  
  <p>But if the user decides to use the fileupload again and upload a new file, the new file will overwrite the previous one. Since they're being saved with the same name.</p>
  
  <p>How then can you ensure that if the file already exists (a file with that exact name is present in the location) it doesn't get overwritten but, I don't know, gets assigned a (1) in the name or something, keeping both files?</p>