我有这个 PHP 代码可以将文件从一个目录复制到另一个目录,而且效果很好,但是,如何只复制以字母“AUW”(减引号)结尾的文件?请记住,该文件是无扩展名的,因此它实际上以字母 AUW 结尾。
同样在复制后,我不希望从源文件夹中删除文件。
// 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);
}