[英]How to write a list of file names to a .lst file using bash commands
我是linux的新手,並試圖在我試圖編寫的PHP腳本中使用bash命令,我需要從我正在迭代使用PHP中的DirectoryIterator()的目錄中編寫每個PDF文件名。一個.lst文件,我坐在另一個文件夾中,並在文本文件的新行中列出每個文件名。
.lst文件應如下所示:
次數1.pdf
2.pdf
3.PDF
...
我希望這是有道理的。 任何幫助/方向將不勝感激。
這是我到目前為止提出的代碼:
// 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++;
}
$fh = fopen("foo.lst", "w");
foreach ($srcDir as $entity)
fwrite($fh, $entity->getFilename() . "\n");
fclose($fh);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.