我正在编写一个小脚本,将一个目录中具有特定扩展名的文件复制到另一个目录。 目前我有:
<?php
$targetDir = "D:\\test dir\\";
$files = glob("C:\\old dir\\*.txt");
foreach ($files as $tocopy) {
copy($tocopy, $targetDir);
}
?>
但是这似乎不起作用。我可以 print_r 文件并找到它们,但不会复制。 如何将扩展名为 .txt 的文件复制到不同的目录中?
最佳答案
您还需要将文件名添加到目标中。类似以下内容应该会有所帮助。
$targetDir = "D:\\test dir\\";
$files = glob("C:\\old dir\\*.txt");
foreach ($files as $file) {
copy($file, $targetDir . $file);
}
关于php - 复制具有特定扩展名 php4 的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21309716/