the php script below select and elaborate one by one all .txt files contained in a specific directory. First of all, a file is copied in a subdirectory named “copy”, after the script calls read.php so that the file is analyzed and elaborated. Finally the same file can be deleted from the main directory.
This is done to all files in the folder, until they end.
THE ISSUE: unfortunately the script stops when a 0 KB file (empty) is found. Probably the problem is read.php but I can’t modify this. So I’d like to delete automatically these unwanted empty files so that the process go on regularly.
Any suggestion? TNX
<?php
$files = glob( '*.txt' );
array_multisort(
array_map( 'filemtime', $files ),
SORT_NUMERIC,
SORT_ASC,
$files
);
$filename="$files[0]";
foreach($files as $filename) {
copy($filename,"./copy/$filename");
echo "<b> $filename </b>File copied<br>";
include ("read.php");
sleep(4);
unlink($filename);
echo "$filename elaborated and deleted from the main folder.<br>";
}
?>
use
filesize()– http://php.net/manual/en/function.filesize.php – to determine the size of the file, and delete anything that is zero.