I have this PHP code to copy files from one directory to another and it works GREAT, however, how do I copy ONLY files ending with the letters “AUW” (minus quotes)? Keep in mind that the file is extensionless so it really ends with the letters AUW.
Also after copying I don’t want the files to be deleted from the source folder.
// Get array of all source files
$files = scandir("sourcefolder");
// Identify directories
$source = "sourcefolder/";
$destination = "destinationfolder/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
1 Answer