[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]
On Wed, 24 Dec 2008 13:58:04 +0000, Simon Robert <simon.robert@xxxxxxxxxxxxxxxxxxxxxx> wrote: >On Wed, 2008-12-24 at 10:27 +0000, Henry Bremridge wrote: >> On Wed, Dec 24, 2008 at 09:49:45AM +0000, Simon Robert wrote: >> >> > I need to rename, for example, cindi_001-l.jpg to cindi_001.jpg. >> > >> > The cms app that this site runs has a rename app using regular >> > expressions. I've tried, but can't get it to work, would anyone know the >> > regexp for the above change? >> > >> >> You want to rename all files removing the "-l"? >> >> i.e. >> >> cindi_001-l.jpg to cindi_001.jpg >> cindi_002-l.jpg to cindi_002.jpg >> Simon, can you confirm you are trying to rename *-1.jpg -> *.jpg ? are all the files in the same directory? can you try the following test code and see of it works? (change ftpserver/user/password/startdirectory to suit your system) - note it does not do any renameing yet! lines after ### have been wrapped by my mailer #!/usr/bin/perl use strict; use warnings; use Net::FTP; # for the ftp upload stuff my $simulate = "true"; my $ftpserver = "192.168.1.18"; my $user = "ftpuser"; my $password = "ftppassword"; my $startdirectory = "/testdir"; my $ftp; my ($name, $newname, $rename); &ftp_open; my @oldname = $ftp->ls; foreach $name (@oldname) { $newname = $name; $newname =~ s/\-1\.jpg/\.jpg/; $rename = !($name eq $newname); if ($rename) { print "rename $name to $newname\n"; } } &ftp_close; sub ftp_open { ### print "using server $ftpserver with user/pass = $user/$password\n"; ### $ftp = Net::FTP->new($ftpserver) or die "cannot connect to $ftpserver"; $ftp->login($user,$password) or die "cannot login"; $ftp->cwd($startdirectory); } sub ftp_close { $ftp->quit; } I will also email this direct to you as an attachment -- http://www.morgad.co.uk/index.html DP: http://www.pgdp.net NTP: http://www.pool.ntp.org L&B: http://www.lynton-rail.co.uk -- The Mailing List for the Devon & Cornwall LUG http://mailman.dclug.org.uk/listinfo/list FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html