473,372 Members | 1,114 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,372 software developers and data experts.

Copy files from one directory to another


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..
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 4111
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

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...
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...
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...
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...
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...
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...
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...
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
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. ...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.