in reply to Newbie needs help replacing files in a directory

You haven't explained how you want to map the "new .html files" to the old "original" names.

Can you give an example to go along with your description of the problem?

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Newbie needs help replacing files in a directory

Replies are listed 'Best First'.
Re: Re: Newbie needs help replacing files in a directory
by Anonymous Monk on Oct 30, 2003 at 20:14 UTC
    Sorry, I really don't understand what you mean by "Map". I have an html file called new.html that exists in the directory. I need that code to replace the code in every other html file in the same directory. This is a one time run. I am really a newbie so excuse this mess but might help explain ... #!usr/bin/perl $newfile = newfile.html $directory = /will/be/abs/path open(dir,$directory); $files=@file; foreach $file { if ($file =~ \.html) { $filename = $file; del($filename); copy($newfile, newfile.dat); ???? rename(newfile.dat, $filename); ??? } } As you can see, I am pretty much clueless...

      I'm assuming you are on Windows, otherwise I'd suggest doing this without perl. I'm not even sure that I understand what you want. I think you want something like this...

      #!/usr/bin/perl -w use strict; use File::Copy qw( cp ); opendir D, '.'; my @files = grep /\.html$/, readdir( D ); for ( @files ) { next if $_ eq 'new.html'; cp $_, "$_.bak"; cp 'new.html', $_; }

      -sauoq
      "My two cents aren't worth a dime.";