I used this to recursively process a directory tree and upload the files
via ftp, you should be able to get what you need from it,

sub uploadfiles {
        my($localpath, $remotepath) = @_;
        (opendir(DIR, $localpath) && print "Processing the " .
$localpath . " directory\n") || (print "Failed to open $localpath\n");
        foreach my $element ( my @dirlist = readdir DIR ) {
                next if ($element =~ /^\.{1,2}$/);
                my $localelementpath = $localpath . '\\' . $element;
                my $remoteelementpath = $remotepath . '/' . $element;
                if(-d $localelementpath) {
                        $ftp->mkdir($remoteelementpath) && (print
"Created dir " . $remoteelementpath . "\n");
                        uploadfiles($localelementpath,
$remoteelementpath); # recursive call
                }
                else {
                        print "Preparing to upload " . $localelementpath
 . "\n";
                        ($ftp->type("I") && print "Transfer mode:
Binary\n") if (-B $localelementpath);
                        ($ftp->type("A") && print "Transfer mode:
ASCII\n") if (-T $localelementpath);
                        $ftp->put($localelementpath, $remoteelementpath)
&& print "Uploaded to " . $remoteelementpath  . "\n";
                }
        }
}

Hope this helps,
Nigel

>>> "Jayashankar Nelamane Srinivasarao"
<[EMAIL PROTECTED]> 06/21/02 01:04pm >>>
Hi All

Please tell me how to proceeed. I have been successfull with writing
the script for going through the directory and executing a command.

But I have tried in vain to modify this code to be able to
recursively run the command through the whole sub-directories,
whichever is
there.

The following is the code I have started. Is this the right approach
are
is there any simpler way of browsing through the directories.

#TEMPLATE TO BROWSE THROUGH A DIRECTORY STRUCTURE
$rootdir="C:/Temp/Test/";
chdir($rootdir);

#We are in /1/@
opendir(DIR1,$rootdir);

@dirfirstlevel=readdir(DIR1);

shift(@dirfirstlevel);
shift(@dirfirstlevel);
foreach $directory (@dirfirstlevel)
{
   if(-d $directory)
   {
       `copy $directory $directory.bak`;
        print "$directory\n";

        }
}

This code however assumes that the directory tree is fixed. How do I
do this when I do not know the depth of the directory C:/Temp/Test

I would like to copy  all the subdirectories under C:/Temp/Test to
..bak

TIA and Regards
Jay




 Jayashankar N S
 Team Ulysses
 Transco ODC
 Wipro Technologies,
 # 72, Tower 6, First Floor,
 Keonics Electronic City, Hosur Road,
 Bangalore-561229,
 India.
 Board: 91-80-8520408, 8520416 Ext 6196
 Dial Com: 792



ITM Business Solutions
Unit 4
Nine Trees Trading Estate
Morthen Road
Rotherham
S66 9JG

Reception
Tel: 01709 703288
Fax: 01709 701549

Help Desk
Tel:01709 530424
Fax: 01709 702159

CONFIDENTIALITY NOTICE: This message is intended only for the use of
the individual or entity to which it is addressed, and may contain
information that is privileged, confidential and exempt from disclosure
under applicable law.



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

Reply via email to