Connecting Tech Pros Worldwide Help | Site Map

Script to copy files from one folder to another

Newbie
 
Join Date: Feb 2009
Posts: 2
#1: Feb 4 '09
Hi, I'm looking for a script to copy transaction log backup files from a network drive I have mapped to a local folder. Part of the filenames are common

dbname_tlog_datehour.trn (date is formated y/m/d and is 24 hour format ex: 1600, 1700, 1800....)

I've searched some perl forums and found a few scripts to try but haven't had any luck getting this working. Any help is appreciated.
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Feb 4 '09

re: Script to copy files from one folder to another


We don't have any scripts. Do you know perl? Have to tried to write the code yourself? Are you having problems with your code?

--Kevin
Newbie
 
Join Date: Feb 2009
Posts: 2
#3: Feb 11 '09

re: Script to copy files from one folder to another


Thanks for the reply Kevin. I know very little perl. I forgot to post the code that I was trying to get working. I managed to figure to figure it out. I'll make sure to post the code and error next time.

Ange
Icecrack's Avatar
Expert
 
Join Date: Sep 2008
Location: Sydney, Australia
Posts: 173
#4: Feb 12 '09

re: Script to copy files from one folder to another


Here is one i made and use.

Expand|Select|Wrap|Line Numbers
  1. use File::Copy;
  2.  
  3. $dir="\\\\Server\\logs\\"; # make sure you add the backslashes on the last directory
  4. opendir(DIR, $dir) or die "can't opendir $dir: $! \n";
  5.  
  6. @files=readdir(DIR);
  7. closedir DIR;
  8.  
  9. foreach $file (@files) {
  10.   if (-f "$dir$file") {  
  11.  
  12. $moveloc="C:\\backup\\logs\\$file"; # Make sure the directory is already made.
  13. $old = "$dir$file";
  14. $new = "$moveloc";
  15. copy($old, $new) or die "Copy Faild: $!";
Reply