[Cascavel-pm] Comparacao de diretorios e manipulacao de arquivos.

Nelson Ferraz nferraz em phperl.com
Sexta Fevereiro 27 10:40:47 CST 2004


Leandro Costa wrote:

> Entao o script que preciso desenvolver:
> 
> Seria o seguinte:

foreach my $tt2 (@ARGV) {
   my ($html) = $tt2 =~ s/\.tt2/\.html/i;

   my $tt2_mtime  = (stat($tt2))[9];
   my $html_mtime = (stat($html))[9];

> - primeiro ele verifica se jah existe o arquivo html
> -arquivo html  existe ?
   if (-f $html) {
>     Sim - verifca a data do arquivo .t2t  data maior ? "executa $
> txt2tags -t html nomedoarquivo.t2t"   - data menor nao faz nada.
     if ($tt2_mtime > $html_mtime) {
       system("txt2tags -t html $tt2");
     }
>     Nao - $ txt2tags -t html nomedoarquivo.t2t
   } else {
     system("txt2tags -t html $tt2");
   }
}

Para executar o script acima, você deve passar os nomes de arquivo 
através da linha de comando. Exemplo: ./script.pl *.tt2

Talvez você prefira reescrever todos os ifs/elses da seguinte forma:

if (!-f $html or $tt2_mtime > $html_mtime) {
   system("txt2tags -t html $tt2");
}

Em outras palavras: execute o comando se o arquivo html não existe, OU 
se a data do arquivo tt2 for maior que a do arquivo html.

OBS - eu não testei nenhuma parte deste código.

-- 
[]s

Nelson

________________________________________________________________
Nelson Ferraz

GNU BIS: http://www.gnubis.com.br
PhPerl:  http://www.phperl.com




Mais detalhes sobre a lista de discussão Cascavel-pm