Title: RE: Help moving sub-directories in Perl...

It is not clear from your code, but I'm assuming that 8am, 12pm, and 5pm are directories, which is what your subject line implies.

You need to check the return value and print the $! variable if the call to the move function returns false.

That is,

move("N:/Ora_Hot_Bkup/PROD/8am","N:/Ora_Hot_Bkup/PROD/$dir_path/")
    or die "8am move failed: $!\n";
move("N:/Ora_Hot_Bkup/PROD/12pm","N:/Ora_Hot_Bkup/PROD/$dir_path/")
    or die "12pm move failed: $!\n";
move("N:/Ora_Hot_Bkup/PROD/5pm","N:/Ora_Hot_Bkup/PROD/$dir_path/")
    or die "5pm move failed: $!\n";

In my testing, the second move command failed with a "Permission denied" error.

The following code should move the directories without error:

move("N:/Ora_Hot_Bkup/PROD/8am","N:/Ora_Hot_Bkup/PROD/$dir_path/8am")
    or die "8am move failed: $!\n";
move("N:/Ora_Hot_Bkup/PROD/12pm","N:/Ora_Hot_Bkup/PROD/$dir_path/12pm")
    or die "12pm move failed: $!\n";
move("N:/Ora_Hot_Bkup/PROD/5pm","N:/Ora_Hot_Bkup/PROD/$dir_path/5pm")
    or die "5pm move failed: $!\n";

The code for the move function in the Copy.pm module can be studied to see why the latter works as expected.

Gary

-----Original Message-----
From: Denmark Weatherburne [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 23, 2001 10:21 AM
To: [EMAIL PROTECTED]
Subject: Help moving sub-directories in Perl...


Hi S/A's

I'm using Active Perl on Win NT.
I'm can't find the correct syntax to move a directory using Perl.
This is my script:

Note the three lines beginning with move near the end.
Those lines don't get executed at all, and no error is generated.
All other lines are executed.
Please point out my error or give me suggestions.


use Time::localtime;
use File::Path;
use File::Copy;

$year = localtime->year() + 1900;
$mon = localtime->mon() + 1;
$day = localtime->mday();
$yesterday = localtime->mday() - 1;
$dummy = 0;

if ($mon >= 10)
{
$dir_path = $year.$mon.$yesterday;
}
if ($mon < 10)
{
$dir_path = $year.$dummy.$mon.$yesterday;
}
printf "Year is %s\n", "$year";
printf "Month is %s\n", "$mon";
printf "Day is %s\n", "$day";
printf "Yesterday was %s\n", "$yesterday";
printf "Path to be created is %s\n", "$dir_path";

rmtree(["\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/$dir_path"],1,1);
mkpath(["\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/$dir_path"],1,0700);

#move(["\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/8am","\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/$dir_path"]);
#move(["\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/12pm","\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/$dir_path"]);
#move(["\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/5pm","\\\\Nawalbe/Shared/Ora_Hot_Bkup/PROD/$dir_path"]);
move("N:/Ora_Hot_Bkup/PROD/8am","N:/Ora_Hot_Bkup/PROD/$dir_path/");
move("N:/Ora_Hot_Bkup/PROD/12pm","N:/Ora_Hot_Bkup/PROD/$dir_path/");
move("N:/Ora_Hot_Bkup/PROD/5pm","N:/Ora_Hot_Bkup/PROD/$dir_path/");

print "Press <Enter> to continue...";
$pause = <>;



Thanks in advance,

Denmark Weatherburne

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to