[Gllug] Changing case on filenames
mriscott at yahoo.co.uk
mriscott at yahoo.co.uk
Wed Mar 6 15:18:46 UTC 2002
> > -----Original Message-----
> > From: Chris Ball [mailto:chris at void.printf.net]
> >
> > #!perl -w
> > opendir(DIR, "/path/to/dir");
> > @files = readdir(DIR);
> >
> > foreach $file (@files) {
> > rename($file, (lc $file));
> > }
>
> It does but only if you are in the directory with the files. Can someone
> tell me why this is as I cannot figure out why you have to be in the same
> directory if you have already opened it in the script or am I doing
> something wrong.
Because you are using the filename only in the rename bit.
ie. you are effectively doing:
$ ls /path/to/dir/
HELLO
GOODBYE
$mv HELLO hello
$mv GOODBYE goodbye
Clearly the moves will only work if you're in the right dir.
To get it to work anywhere, you want:
#!perl -w
$dir="/path/to/files";
opendir(DIR, $dir);
@files = readdir(DIR);
foreach $file (@files) {
rename("$dir/$file", (lc "$dir/$file"));
}
Ian
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list