in reply to Newbie needs help replacing files in a directory
Here's a sample of how you might do it on a win32 box. It's very brute-force but does the job. It assumes that the file that you will be replacing all of the others with is named 'replacer_file.html' and resides in the same directory as the files to be replaced.
use strict; use File::Copy; use constant REPLACEMENT_FILE => 'replacer_file.html'; use constant DIRECTORY => 'C:/foo/'; opendir(FOO, DIRECTORY); my @file_list = grep /\.html?$/, readdir FOO; for my $file (@file_list) { unless ($file eq REPLACEMENT_FILE) { unlink(DIRECTORY . $file); #remove original copy DIRECTORY . REPLACEMENT_FILE, DIRECTORY . $file; #make copy o +f replacer & rename to original } } closedir FOO;
Hope this helps you along. One of the other monks may have a more elegant & idiomatic way of accomplishing this.
|
|---|