Forum Moderators: phranque
I have 2,000 html files on the server
that needs to be renamed htm -> HTML
I'm using leapFTP, that can't be done.
I remember CuteFTP has batch rename.
but my trial version has expired.
Is there a free FTP'er that supports batch rename?
Thanks for your kind help :)
[perl]#!/usr/bin/perl
# specify a directory where all your files are located
# note: you must have a trailing slash
my $dir = "./";
opendir(DIR, $dir) or die 'Cannot read directory';
my @files = grep(!/^(\.\.?)$/, readdir(DIR) );
closedir(DIR);
foreach my $filename (@files ) {
if ( $filename =~ /^(.+)\.htm$/ ) {
$filename = $1;
rename $dir.$filename.'.htm', $dir.$filename.'.html';
}
}[/perl]
I modified your script a bit for use from the browser...but I know almost no Perl, and I'm drawing from a bit of C++ experience combined w/ Perldoc, so please correct me if I messed up anywhere...I made it output the files changed and the extensions to change are a little easier to get to as variables...
#!/usr/bin/perl
# use CGI::Carp qw(carpout fatalsToBrowser);
# specify a directory where all your files are located
# note: you must have a trailing slash
my $dir = "./";
# specify old and new file extensions
# note: don't include the dot (.)
my $ext = "htm";
my $extnew = "html";
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Renaming files..</title>\n";
print "</head>\n";
print "<body>\n\n";
opendir(DIR, $dir) or die 'Cannot read directory';
my @files = grep(!/^(\.\.?)$/, readdir(DIR));
closedir(DIR);
foreach my $filename (@files) {
if ($filename =~ /^(.+)\.\Q$ext/) {
$filename = $1;
my $tmp = $dir . $filename;
rename $tmp . '.' . $ext, $tmp . '.' . $extnew;
print "<div><b>Renamed:</b> $tmp.$ext</div>\n<div><b>To:</b>
$tmp.$extnew</div><br />\n\n";
}
}
print "</body>\n";
print "</html>\n";
undef $dir;
undef $ext;
undef $extnew;
undef @files;
undef $filename;
undef $tmp;
exit;
Jordan