473,416 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Copy files from one directory to another

Hi,

I am trying to do this perl script, but not able to complete it successfully.
Here is the description what the script has to do..

Accept two and only two command line arguments. Again, these will be the names of two directories. This time, make sure that the "sending" directory exists (and is, indeed, a directory). Make sure that the "receiving" directory exists, and if not, create it. Then, copy files from the sending directory to the receiving directory. Copy only those files that have a suffix of ".log", and are not empty. That is, only copy the .log files that actually contain some data. When you copy these files, change the suffix of the filenames in the receiving directory from ".log" to ".abc". Again, display a count of the number of files copied. And one last thing: These log files will contain two columns of data. When you copy the files, switch the order of the columns in the files you create in the receiving directory.

The script i wrote for this is..
#!/usr/bin/perl
use strict;
use warnings;
#Check to be sure exactly 2 arguments passed to script
die "Must pass exactly 2 arguments to script" if @ARGV != 2;

# assign meaningfull names to variables
my $source = $ARGV[0];
my $target = $ARGV[1];

# Check to see if First argument is a directory
# if not exit

die "$source is not a directory \n" if !-d $source;

if !-d $target;
{ # Create Target Directory
mkdir $target, 0755;
}

#copy all files with a .log extension to the target directory
# renaming the extension to abc

my $filecount = 0;

foreach my $entry (readdir DH) {
my $file = "/$target/$entry";
print " the file name is $file\n";
}
my ($file, $name);
next unless $file =~ \/.log$/ and !-z $name;
my $newfile = /$target//$file;
$newfile =~ s/\.log$/.abc/;
$filecount += 1;


# Print the number of files copied
printf "The number of files copied is: %d\n", $filecount;
$filecount = 0;
Mar 22 '07 #1
1 4118
KevinADC
4,059 Expert 2GB
Your code is full of syntax errors, and it reads just like a classroom assignment.
Mar 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
11
by: Mike | last post by:
I want to be able to copy a directory of files (all .HTM files) from a network drive to a local drive on the machine c:\HTMFiles , How can i do that? I tried File.Copy(source, dest) but i need...
3
by: Johnny | last post by:
Hi, I have created an ASP.NET application (let's call it FooBar) with VS.NET on my local machine, residing in http://localhost/FooBar. Deploying it to another folder on my machine works well...
2
by: Bob | last post by:
Cannot copy assembly '<...>' to file <...>.dll'. The process cannot access the file because it is being used by another process. Could not copy temporary files to the output directory. The file...
5
by: Frank | last post by:
I'm using VB .NET and I'm finding that CopyTo will not help me copy all the files in one directory to antoher directory at one time. Which command (if that's the word) do I use to copy ALL the...
12
by: samoore33 | last post by:
I found a real nice article on how to copy a directory on MSDN. The only problem is that I can not figure out how to get the namespace Microsoft.VisualBasic.MyServices. I wanted to know if anyone...
4
by: GS | last post by:
from the online help, looks like to code step by step to copy content of directory to another whereas I can use online line code for directory move or delete. I am using 2005 express .net 2 I did...
4
by: Masta | last post by:
Hello Group. I have a directory with 3000 ".jpg" named like this: 1234_01.jpg 1234_09.jpg 1234_11.jpg 1234_12.jpg 2341_01.jpg 2341_05.jpg
2
by: foss | last post by:
hi all, I am not able to copy file from a directory in the server to another directory. Here, the source is outside the web root directory and the destination is inside the web root directory. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.