in reply to Re: Newbie needs help replacing files in a directory
in thread Newbie needs help replacing files in a directory

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...
  • Comment on Re: Re: Newbie needs help replacing files in a directory

Replies are listed 'Best First'.
Re: Re: Re: Newbie needs help replacing files in a directory
by sauoq (Abbot) on Oct 30, 2003 at 20:31 UTC

    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.";