Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use File::Copy to copy whole directories? 3

Status
Not open for further replies.

Jimbo2112

IS-IT--Management
Mar 18, 2002
109
GB
Hi All,

I am using Perl on NT4 FYI.

Can you use File::Copy to copy directories and their contents? My code does not throw up any errors even using use strict, but it does not move the directories either!

Here is the code in question:

#Copy the files across
foreach (@divs)
{
print "\n Copying ".$jobname."\\".$_." to ".$workroot;
copy ($jobname_full."\\".$_ ,"$workroot");
}

Any ideas on what code is needed to copy the whole directory?

Cheers

Jimbo
 
Hello Jimbo,

I would use a combination of File::Find and File::Copy to do the job you want.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Thanks Mike,

After speaking to someone else I now know of a module called File::NCopy, but it is not generally listed on CPAN and the only versions I could find on the web were Linus based. Unless someone replies to this post I will create a new thread where I ask for the source code for File NCopy that is not GNU tarred and zipped for me to install.

Failing that I will create a loop in a loop to copy all the files! Unix was never this hard!

Cheers

Jimbo
 
:)

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
If you're using ActiveState perl, there's a ppd in their repository -

File-NCopy [0.32] Copy file, file Copy file | dir, dir

to install: C:\>ppm install file-ncopy

 
I should really preview my posts :)

That should be -

File-NCopy [0.32] Copy file, file Copy file(s) | dir(s), dir

to install: C:\>ppm install file-ncopy
 
Chaz,

Thanks for this. I actually found the module I needed by googling for the exact module name (ncopy.pm). But when I installed it it still id not work! So I did it the long way, which may be of use to some folk who are learning like I am. Check the code below. You will have to change the varaibles for your own needs but the structure is there!

# #Copy the files across
foreach $divname(@divs)
{
print " Copying ".$jobname."\\".$divname."\n";
mkdir $workroot."//".$divname;
opendir DIR, $jobname_full."//".$divname;
@temp_files = grep /.*/, readdir DIR;
close DIR;
foreach $rawfile(@temp_files)
{
copy ($jobname_full."\\".$divname."\\".$rawfile , $workroot."\\".$divname);
}
}

Remember to use the File::Copy module though!

Cheers

Jimbo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top