php 空文件,当一个文件是空的php时如何删除它?

我有多个文件。我的脚本在文件中搜索序列名和序列。如果找到了,格式将从gb改为fasta,只保留序列名和序列并将其写回文件中。但有时文件不包含序列名。在这种情况下,我不会在文件中写入任何内容,文件是空的。应该删除这些文件,因为在我的脚本结束时,将从所有这些文件创建一个multifasta。

# Find all gb files

$files = glob("*.gb");

foreach ($files as $filename){

$newname = basename($filename, ".gb"). ".fasta";

rename($filename, $newname);

$condition = false;

$lines = file($newname);

foreach($lines as $line) {

if (strstr($line, "ACCESSION") ) {

# Find the line containing the sequence name

$head = str_replace("ACCESSION ","",$line);

$final = "> " . $head;

# check if $head contains text

if ($head == ""){

$condition = true;

}

}

$sequence = trim($line);

# Find the sequence and check the condition

if (preg_match('/^\d/', $sequence) && $condition == false){

$sequence = preg_replace('/[0-9]+/', '', $sequence);

$sequence = preg_replace('/\s/',"",$sequence);

# Store in string

$out .= $sequence;

}

}

# Read lines into file

$f = fopen($newname, "w");

fwrite($f, $t);

fclose($f);

}

# Create multifasta

exec('for f in *fasta; do cat "$f"; echo; done > db', $return);

当文件为空时,我如何才能最好地删除它,这样它就不会被插入到multifasta中。我相信这很简单,但我不知道怎么做。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值