I am new to linux and trying to work with bash commands within a PHP script that I'm attempting to write, I am needing to write each PDF file name from a directory that I'm iterating through using the DirectoryIterator () in PHP to a .lst file that I have sitting in another folder and have each file name listed on a new line in the text file.
The .lst file should look like this:
1.pdf
2.pdf
3.pdf
...
I hope this makes sense. Any HELP/DIRECTION would be greatly appreciated.
Here is the code that I've come up with so far:
// Use the command line cp to copy each PDF file in the sourceDir to the destinationDir.
foreach ($srcDir as $entity) {
/**
* @var DirectoryIterator $entity
*/
/*$result = rename($sourceDir . '/' . $entity->getFilename(), $destinationDir .'/' . $entity->getFileName());
if(!$result)
{
throw Exception('Could not copy file ' . $entity->getFilename() . 'to destination directory ');
}*/
$cpString = 'cp ' . $sourceDir . '/' . $entity->getFilename() . ' ' . $destinationDir .'/' . $entity->getFileName() . ' 2<&1';
passthru($cpString, $returnVar);
if($entity->isFile() && strtoupper($entity->getExtension()) == 'PDF')
{
$cpString = 'cp ' . $sourceDir . '/' . $entity->getFilename() . ' ' . $destinationDir .'/' . $entity->getFileName();
if ($counter = 1) {
$catString = 'cat ' . $destinationDir . '/' . $batchNum . '.lst';
}
$cpString = ''
}
$counter++;
}