Chris,
Thank you for your help. I have listed the complete script.
If I use mkpath( $targetDirectory );, I get an error:
$ ./AutoBuildAgent.pl -install Template_LOGF_Bv410
Enter the New Agent Name which you want to upgrade to 5.0 :
Template_LOGF_Bv410Enter the Parameter Name used in main.par ( Second
Section ): r4.1
Enter the target directory [C:\Program
Files\esecurity5.0\wizardlements\Template_LOGF_Bv410]:
Template_LOGF_Bv410, r4.1, C:\Program
Files\esecurity5.0\wizardlements\Template_LOGF_Bv410
files are being copied .....to C:\Program
Files\esecurity5.0\wizardlements\Template_LOGF_Bv410
Undefined subroutine &main::mkpath called at ./AutoBuildAgent.pl line
86, <STDIN> line 3.
And If I comment mkpath( $targetDirectory ); the script does not copy
the file, but does not give me any error
Can you please help me ?
Thanks,
-Kamal.
Complete Code:
#!/usr/bin/perl -w
#use strict;
no warnings;
use File::Copy cp;
#use File::Find;
#use File::Path;
#
#STEPS:
#
#1. COPY 4 files (auto.tem, auto.asd, auto.lkp and auto.par) , these
files will be delivered with the zip
#ask for or display a choice of *.tem file(s)
#
#2. TEMPLATE NAMES
#e.g rename Parsing.tem to main.tem , This template can be different
name than Parsing.tem, hence the user will
# be prompted with the name first, and then the *.tem will be replaced
with main.tem
#
#2. EDIT main.par , goto the second section, and replace e.g
# FORM: Parameters
# ParameterCount: 22
# Parameter: "r4.1"
# Parameter: "message.bmp"
# Parameter: "300"
#3. replace "r4.1" to "main", please note that the string might NOT be
"r4.1"
# the 4 files will be included in the zip delivered to the customer,
along with perl.exe for windows, and perl needs
# to be installed on Solaris.
# GLOBAL VARIABLES
my $MYPATH = $ENV {'WORKBENCH_HOME'};
my $MYPATH2 = $ENV {'ESEC_HOME'};
my $perl_path = "$MYPATH\Elements";
#print "This is the Windows path: ", win_path($perl_path), "\n";
$infile_tem ="auto.tem";
sub win_path {
(my $path = shift) =~ tr!/!\\!;
return $path;
}
#MAIN
opendir(DIRHANDLE, "$MYPATH/Elements") || die "Please install Wizard
on this machine: $!\n";
closedir(DIRHANDLE);
$newAgentName = &promptUser("Enter the New Agent Name which you want to
upgrade to 5.0 ");
$mainParParameter = &promptUser("Enter the Parameter Name used in
main.par ( Second Section )");
$targetDirectory = &promptUser("Enter the target directory ",
"$perl_path\\$newAgentName");
print "$newAgentName, $mainParParameter, $targetDirectory\n";
#print "Please install Wizard on this machine\n";
#$infile_tem ="auto.tem";
#$outfile_tem ="auto.tem";
#$infile_asd ="auto.asd";
#$outfile_asd ="auto.asd";
#$infile_lkp ="auto.lkp";
#$outfile_lkp ="auto.lkp";
#$infile_par ="auto.par";
#$outfile_par ="auto.par";
my $oldfile = "auto.tem";
my $newfile = "auto.tem";
print "files are being copied .....to $targetDirectory\n";
#system('cp "auto.tem" "$targetDirectory\auto.tem"');
mkpath( $targetDirectory );
cp (auto.tem , $targetDirectory);
# rename file Parsing.tem ( in most cases ) to main.tem, in this case
user needs to be prompted for the *.tem file,
# and the user input will be stored
# as a Variable used in this sub
sub renameTemplate{
}
# edit the file main.par created in the sub renameTemplate{} and replace
Parameter: "r4.1" in the second section to main.par
# please keep in mind that the Parameter could be any string other than
r4.1, hence the Parameter needs to be parsed,
# and then replaced
# with "main"
sub edit{
}
sub promptUser {
$defaultValue = "";
#-------------------------------------------------------------------#
# two possible input arguments - $promptString, and $defaultValue #
# make the input arguments local variables. #
#-------------------------------------------------------------------#
local($promptString,$defaultValue) = @_;
#-------------------------------------------------------------------#
# if there is a default value, use the first print statement; if #
# no default is provided, print the second string. #
#-------------------------------------------------------------------#
if ($defaultValue) {
print $promptString, "[", $defaultValue, "]: ";
} else {
print $promptString, ": ";
}
$| = 1; # force a flush after our print
# get the input from STDIN (presumably the keyboard)
$_ = <STDIN>;
#------------------------------------------------------------------#
# remove the newline character from the end of the input the user #
# gave us. #
#------------------------------------------------------------------#
chomp;
#-----------------------------------------------------------------#
# if we had a $default value, and the user gave us input, then #
# return the input; if we had a default, and they gave us no #
# no input, return the $defaultValue. #
# #
# if we did not have a default value, then just return whatever #
# the user gave us. if they just hit the key, #
# the calling routine will have to deal with that. #
#-----------------------------------------------------------------#
if ($defaultValue) {
return $_ ? $_ : $defaultValue; # return $_ if it has a value
} else {
return $_;
}
}
--------------------
-----Original Message-----
From: Gerber, Christopher J [mailto:[EMAIL PROTECTED]
Sent: Friday, October 15, 2004 3:36 PM
To: Kamal Ahmed; [EMAIL PROTECTED]
Subject: RE: Copying Files in Perl
> I want to use the following pm's to copy files.
>
> (CODE SNIPPIT)
>
> use File::Copy;
> use File::Find;
> use File::Path;
>
> my $MYPATH = $ENV {'WORKBENCH_HOME'};
> my $MYPATH2 = $ENV {'ESEC_HOME'};
>
> $newAgentName = &promptUser("Enter the New Agent Name which you want
> to
upgrade to 5.0 ");
> $mainParParameter = &promptUser("Enter the Parameter Name used in
> main.par
( Second Section )");
> $targetDirectory = &promptUser("Enter the target directory ",
"$perl_path\\$newAgentName");
>
> Now I want to use cp command from File::Copy to copy fileA to
> $targetDirectory
Kamal,
File::Find is a great module, but you didn't provide any insight into
what you wanted to do with it. To answer you explicit question, and one
implied
question:
mkpath( $targetDirectory );
cp( $fileA, $targetDirectory );
Note1: Change "use File::Copy;" to "use File::Copy cp;".
Note2: I assumed that "fileA" referred to a variable called $fileA.
Chris
LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may
be privileged. It is intended for the addressee(s) only. Access to this
E-mail by anyone else is unauthorized. If you are not an addressee, any
disclosure or copying of the contents of this E-mail or any action taken
(or not taken) in reliance on it is unauthorized and may be unlawful. If
you are not an addressee, please inform the sender immediately.
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs