title: Perl script that copies files listed in text file only copies the last file successfully
body: <p>I have a Perl script that reads in a list of files from a file, <code>accessFiles.txt</code>,  and copies them to another location.</p>
  
  <pre><code>open my $accessFiles, "$scriptDir\\accessFiles.txt" or die "Could not open access file list $!";
  
  while (my $accessFile = &lt;$accessFiles&gt;) {
      my($file, $dir, $ext) = fileparse($accessFile, qr/\.[^.]*/);
      my $accessDir = "$localDir\\AccessFiles\\$file";
      my $accessCopy = "$accessDir\\$file$ext";
  
      system("rmdir","/S", "/Q",$accessDir);
      system("mkdir",$accessDir);
      system("copy", $accessFile, $accessCopy);
  }
  </code></pre>
  
  <p>The output of the copy command says it copied one file for each file in <code>accessFiles.txt</code>, but only the last file gets copied. </p>
  
  <p>I've added input statements before and after the copy, and I cannot see any of the other files in the copied directory at any time.</p>
  
  <p>Now, if I change the script to read from an array of files, then it works perfectly.</p>
  
  <pre><code>my @files = ('\\\\sourceshare\acc1.accdb', '\\\\sourceshare\acc2.accdb');
  
  foreach my $accessFile (@files) {
      my($file, $dir, $ext) = fileparse($accessFile, qr/\.[^.]*/);
      my $accessDir = "$localDir\\AccessFiles\\$file";
      my $accessCopy = "$accessDir\\$file$ext";
      system("rmdir","/S", "/Q",$accessDir);
      system("mkdir",$accessDir);
      system("copy", $accessFile, $accessCopy);
  }
  </code></pre>
  
  <p>Thanks in advance.</p>