On Mon, 24 Mar 2003, Rosenstein, Leon wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi everyone,
>
> I am having some problems with a script.
>
> Currently the script reads:
> opendir (DIR, "c:/temp") or die "Cant Open Temp Buddy Boy! \n";
> @filenames = readdir (DIR) or die "Can't Hold Filenames \n";
> foreach $name (@filenames)
> {if ($name eq "blah.dat") {rename ($name, "blah.old") or die "sorry
> couldnt complete task cause $!" } };
readdir returns only the filename, it does not prefix the directory name
before it. You will have to do this
rename ("c:/temp/$name", "c:/temp/blah.old");
But why loop through readdir when you can just do this
# if the file exists rename it
if (-e "c:/temp/blah.dat") {
rename (...);
}
perldoc -f -x # you can choose the appropriate file test for your program
>
> C:\scriptz>perl -w open4.pl
> sorry
> couldnt complete task cause No such file or directory at open4.pl line 7.
>
>
> Yet when I run this code:
>
> opendir (DIR, "c:/temp") or die "Cant Open Temp Buddy Boy! \n";
> @filenames = readdir (DIR) or die "Can't Hold Filenames \n";
> foreach $name (@filenames) {
> print "$name \n"; }
>
> I get:
>
> C:\scriptz>perl -w open3.pl
> .
> ..
> blah.dat
> FAD3.TXT
> osctalk.log
> sec_scan.html
>
> Can anyone explain to me what I am doing wrong?
>
> Thx again,
> leon
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]