Here is the whole program
#!/bin/perl
# 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
$source = @ARGV[0];
$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;
mkdir $target, 0755;
# if !-d $target;
#{ # Create Target Directory
# mkdir $target, 0755;
#}
#copy all files with a .abc extension to the target directory
# renaming the extension to xyz
# chdir $source;
# rename -f
$filecount = 0;
opendir DH, "//$source";
foreach $file (readdir DH)
{ printf " the file name is %s\n", $file;
next unless $file =~ \/.abc$/ and !-z $name;
my $newfile = /$target//$file;
$newfile =~ s/\.abc$/.xyz/;
$filecount += 1;
}
# Print the number of files copied
printf "The number of files copied is: %d\n", $filecount;
The program runs but I get 0 files copied and no files are copied or
renamed.
Brian
"Jim Gibson" <jg*****@mail.arc.nasa.gov> wrote in message
news:190420051608396664%jg*****@mail.arc.nasa.gov. ..
In article <ttf9e.2474$c24.1712@attbi_s72>, b.milbrandt
<b.*********@insightbb.com> wrote:
I am trying to convert a unix shell script to perl, and I have having a
problem with the portion that copies files based on extension and
renaming
them in the process. I only trying to copy files with a non-zero length.
Here is what I have so far.
$target is a command line parameter
$source is a command line parameter
opendir DH, "/$target";
foreach $file (readdir DH)
{ printf " the file name is %s\n", $file;
next unless $file =~ \/.abc$/ and !-z $name;
my $newfile = /$target//$file;
$newfile =~ s/\.abc$/.xyz/;
$filecount += 1;
}
Is this the actual program you are trying to run? You are missing
characters and using the wrong characters in some places. You do not
say what this program is doing wrong. How can anybody help you?
Please post a complete, working, short-as-possible, cut-and-pasted
program that demonstrates the problem you are having, but do it in
comp.lang.perl.misc because this newsgroup is defunct.
Thanks.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---