Rich Fernandez a �crit :
>
> It all started out as a simple script to rename some files.
> Now I can't find my way out!
>
> I have several hundred files that are named like this:
> 'ENDPNA.PROD.HRBANS(EDIFACT)'
>
> Note that the file name includes single ticks, dots, and parens.
>
> Here's what I've done so far:
>
> <snip>
> while (<*>) { # select each source name in the directory
>
> my $file = $_; # Set $file to the filename you just read
>
> s#'.+\((.+)\)'#$1#; # cut out the part you want to keep (basename)
>
> my $target = $_; # Set $target to the new file name
>
> # Now build the full path of the destination directory...
> $target = $DESTDIR . '/' . $target;
>
> # Now escape the leading and trailing single quotes in the original
> # file name ($file)
>
> my $source = "\\";
> $source .= $file;
> $source =~ s#(.+)'#$1\\'#;
> # my $source = quotemeta($file); #Using quotemeta to escape everything
> #doesn't work either
>
> #rename $source, $target or warn "$source: Cannot rename to $target: $!\n";
>
> my @args = ("mv", "$source", "$target");
> system(@args) == 0
> or warn "$source: Cannot mv to $target: $!\n";
>
> }
>
> When I run this script, I get an error that says: A file or directory in
> the path name does not exist.
>
> Can someone please tell me what I'm doing wrong and/or suggest a better
> way to do it?
>
> Thanks!
>
> richf
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
Have a look at Perl in action ...
script rename.pl
#!/usr/bin/perl -w
#rename -reparateur de noms de ficihers de Larry Wall
$op = shift or die "utilisation : rename expr [ficihers]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
then you use it so :
rename.pl 's/\.orig$//' *.orig #this wipe out .orig !
rename.pl 'tr/A-Z/a-z/ unless /^Make/' * #this one change all uppercase
to lowercase in all files !
....
Have a look on other samples in the book
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]