dReKurCe has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to rename all files in a directory based on a regex match of a compund file name.I have followed the example of The Perl Cookbook 9.9
The code as follows generates the following error mesage:Could not rename:Device or resource busy at rename line 22.
#! /usr/bin/perl $dir="/home/yehuda/img/jpg/"; opendir(DH,$dir)or die "FOO BAR! $!\n"; while (defined ($img=readdir DH)){ if ($img=~m/^(.*)\.(.*)\.(.*)/g){$success=1}; if ($sucess==1){ $newname="$1.$3"; }else{ print "$img didn't match\n"; } push @names,$img if $sucess==1; push @newnames,$newname if $sucess=1; } closedir DH; foreach $name(@names){ $i=$i+1 ; $newname_=$newnames[$i-1]; $path="$dir/$name"; $target="$dir$newname_"; rename ($path,$target) or die "Could not rename:$!"; print " $path is now $target \n"; ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Rename All Files In a Directory
by aukjan (Friar) on Jul 01, 2005 at 09:33 UTC | |
|
Re: Rename All Files In a Directory
by anonymized user 468275 (Curate) on Jul 01, 2005 at 09:35 UTC | |
by blazar (Canon) on Jul 01, 2005 at 09:43 UTC | |
|
Re: Rename All Files In a Directory
by blazar (Canon) on Jul 01, 2005 at 09:29 UTC | |
by holli (Abbot) on Jul 01, 2005 at 09:45 UTC | |
by blazar (Canon) on Jul 01, 2005 at 09:57 UTC | |
by holli (Abbot) on Jul 01, 2005 at 10:01 UTC | |
|
Re: Rename All Files In a Directory
by blazar (Canon) on Jul 01, 2005 at 09:51 UTC | |
|
Re: Rename All Files In a Directory
by dReKurCe (Scribe) on Jul 01, 2005 at 10:28 UTC | |
by aukjan (Friar) on Jul 01, 2005 at 11:38 UTC | |
by polettix (Vicar) on Jul 01, 2005 at 11:06 UTC | |
by dReKurCe (Scribe) on Jul 01, 2005 at 12:24 UTC |