我有一个包含3个子文件夹和.txt文件的文件夹,如下所示:
我想要:
我已经完成了此功能,但是它不起作用...我的错误在哪里?
<?php
function deplacementFile( $path ) {
$dir = './test/';
$allFiles = scandir($dir);
foreach($allFiles as $file) {
if (!in_array($file,array(".","..","FR", "ES", "PT")))
{
$file = $dir.$file;
$filename = basename( $file );
//read the entire string
$str = file_get_contents( $file );
if ( strpos( $filename, 'A500_' ) === 0 ) {
$dossierDestination1 = './test/FR/';
if(!copy($dir, $dossierDestination1)) {
echo "error copy";
} else {
if(!unlink($dir)) {
echo "error unlink";
}
}
}
else if ( strpos( $filename, 'A700_' ) === 0 ) {
$dossierDestination2 = './test/ES/';
if(!copy($dir, $dossierDestination2)) {
echo "error copy";
} else {
if(!unlink($dir)) {
echo "error unlink";
}
}
}
else if ( strpos( $filename, 'A900_' ) === 0 ) {
$dossierDestination3 = './test/PT/';
if(!copy($dir, $dossierDestination3)) {
echo "error copy";
} else {
if(!unlink($dir)) {
echo "error unlink";
}
}
}
else {
return false;
}
}
}
}
deplacementFile( './test/' );
echo "Successfully completed!";
?>
这是脚本的升级版本: