Tuesday 15 September 2015

Perl script that copies files listed in text file only copies the last file successfully -


I have a Perl script that reads in the list of files from a file, accessfiles.txt , And copy them to another location.

  Open my $ accessFiles, "$ scriptDir \\ accessfiles.txt" or "Could not open $ file entry file!"; While (my $ accessFile = & lt; $ accessFiles & gt;) {my ($ file, $ dir, $ ext) = fileparse ($ accessFile, qr / /. [^.] * /); My $ accessDir = "$ localDir \\ accessfile \\ $ file"; My $ accessCopy = "$ accessDir \\ $ file $ ext"; System ("RMDIR", "/ s", "/ q", $ accessDir); System ("mkdir", $ accessDir); System ("copy", $ accessFile, $ accesscopy); }   

The copy command output says that a file is copied to accessfiles.txt for each file, but only the previous file was copied is.

I've added the input status before and after the copy, and I can not see any other file in the directory copied at any time.

Now, if I read script from an array of files, then it works perfectly.

  my @files = ('\\\\ sourcehare \ acc1.accdb', '\\\\ sourcehare \ acc2.accdb'); Prefer my $ accessfile (@file) {My ($ file, $ dir, $ ext) = fileparse ($ accessFile, qr / / ^ ^ ^ ^^) My $ accessDir = "$ localDir \\ accessfile \\" $ File "; My $ accessCopy = "$ accessDir \\ $ file $ ext"; System ("RMDIR", "/ s", "/ q", $ accessDir); System ("mkdir", $ accessDir); System ("copy", $ accessFile, $ accesscopy); }   

Thanks in advance.

Add the last line you did not remove

  chomp ($ accessFile );    

No comments:

Post a Comment