![ישן](https://static.fresh.co.il/images/vBulletin/statusicon/post_old.gif)
05-07-2010, 20:47
|
|
|
חבר מתאריך: 23.06.06
הודעות: 20
|
|
מימוש CP של LINUX
היי ערב טוב.
אני מנסה לממש את הפקודה CP בפרל , נכון לעכשיו אני מנסה להעתיק בין 2 תקיות קבועות שהגדרתי בהתחלה , FROM ו TO
הבעיה היא בקריאה הרקורסיבית TO , איפשהו שם הוא נאבד, כלומר הוא מעתיק את הקבצים ,עד לרגע שהוא מגיע לתקיה , ושם הוא פשוט מפסיק.
אם אני מוציא את הקריאה ל COPY הוא מעתיק את כל הקבצים בספריה מסוימת , ומפסק.
אודה מאוד מאוד לעזרה!
קוד:
#!/usr/bin/perl
my $from = $ARGV[0];
my $to = $ARGV[1];
#copyFile("/home/student33/","/home/student33/AF");
copy("/home/student31/","/home/student33/AF");
sub copy()
{
my ($f,$t) = @_;
my $obj;
opendir(handler,$f);# || return copyFile($f,$t);
while( ($obj = readdir(handler)))
{
if (-f $f.$obj)
{
copyFile($f.$obj,$t."/".$obj);
}
if (-d $f.$obj)
{
my $dir =$t.$obj;
mkdir $dir , 0755;
print "copying : ".$f.$obj." to : ".$t."/"."$obj"."\n";
<STDIN>;
if ($obj ne '.' and $obj ne '..')
{
print "ENTERING to ".$f.$obj." -- ".$t."/".$obj."\n";
copy($f.$obj,$t."/".$obj);
}
}
}
#closedir(handler);
#return 1;
}
sub copyFile()
{
my($f,$t) = @_;
open(whereTo,">".$t);
open(fHandler,$f);
print "coping file: ".$f." to : ".$t."\n";
while(<fHandler>)
{
print whereTo $_;
}
close(whereTo);
close(fHandler);
}
|