Hi Leon

"Leon Rosenstein" <[EMAIL PROTECTED]> wrote:
>
> I am having some problems with a script.
>
> Currently the script reads:
>
> opendir (DIR, "c:/temp") or die "Cant Open Temp Buddy Boy! \n";

Don't put \n on the end of a die string, otherwise the Perl interpreter
won't tell you the line number of the failure.

> @filenames = readdir (DIR) or die "Can't Hold Filenames \n";

@filenames now contains a list of the file names only ( without a path ).

> foreach $name (@filenames)
> {if ($name eq "blah.dat") {rename ($name, "blah.old") or die "sorry couldnt complete 
> task cause $!" } };

This will try to rename .\blah.dat

>
> C:\scriptz>perl -w open4.pl
> sorry couldnt complete task cause No such file or directory at open4.pl line 7.

Please try to indicate which is the line in question in your script.
In this case it's obvious because of the die string, but the script you
have shown us only has four lines!

> Can anyone explain to me what I am doing wrong?

You are unlikely to have C:\temp as your current directory, so you will need to
either prefix the name of the file with its path, or do chdir 'C:\temp' before
running the rename. This should do the trick:

    my $dir = 'C:\temp';
    opendir DIR, $dir or die $!;

    while ($name = readdir DIR) {

        next unless $name eq "blah.dat";

        $name = join '\\', $dir, $name;
        rename $name, "blah.old" or die $!;
    }

    closedir DIR;

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to