Forum Moderators: phranque

Message Too Old, No Replies

FTPware that supports batch rename?

batch rename FTP software?

         

affter333

1:34 am on Aug 25, 2003 (gmt 0)



Hi,

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 :)

MonkeeSage

1:56 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't know about an FTP program, but you could download the files and do it locally using a nifty little (freeware) program called "Extension Changer." I've used it for that purpose before.

Jordan

moltar

2:24 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can write a little perl (php, asp) script that will do that for you.

MonkeeSage

2:37 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good point moltar! If only I had known Perl then I could have saved about an hours worth of UL / DL time! Doh!

Jordan

SlowMove

2:53 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're running Windows, try searching for:
magenta rename files

moltar

4:10 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change the $dir variable to the folder where all your files are. Then chmod it to 755 and run it either from shell, or directly from a browser. If you run it from a browser, then you will get a 500 error, but don't worry, your files should be renamed.

[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]

MonkeeSage

4:21 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice! :D

Ps. I didn't hit the 500 error, either, BTW.

Jordan

MonkeeSage

5:46 am on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



moltar:

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

moltar

2:00 pm on Aug 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks fine to me! I didn't run it, but logic is surely correct. Good job :)