Here is my solution thank you for help
......
&my_read_dms_booking_folders('c:/bookings') ;
sub my_read_dms_booking_folders{
my ($bookingspath) = @_ ;
opendir(DIR, "$bookingspath") or die "cant open $bookingspath: $!\n";
while(defined(my $folder = readdir(DIR))) {
if ($folder eq '.') { next ; }
if ($folder eq '..') { next ; }
opendir(DIR_PHONE, "$bookingspath/$folder") or die "cant open
$bookingspath/$folder: $!\n";
while(defined(my $phone_data = readdir(DIR_PHONE))){
if (substr($phone_data,0,8) eq 'PHONELOG'){
&my_read_data_file($bookingspath,$folder,$phone_data);
}
}
closedir(DIR_PHONE) ;
}
closedir(DIR) ;
}#------------------------------------------------------------------------------------------
sub my_read_data_file {
my ($bookingspath,$folder,$phone_data) = @_ ;
my $phonelog = "$bookingspath/$folder/$phone_data";
$bookref = $folder;
open (P1FILE, "$phonelog") or die "can't open $phonelog: $!";
flock (P1FILE, LOCK_SH) or die "can't lock $phonelog: $!";
while (<P1FILE>)
{
chomp;
@linex = split(/\|/);
&plfields;
&build_days;
}
close (P1FILE);
}
.....
Simphiwe Mkhize wrote:
Please Help
I have multiple folders want to read trough each folder and search for
certian file. I have code which is working fine but does not do what I
want. I dont want to hard code path as it read different folder within
sub get_phone_log {
#------------------------------------------------------------------------------------------
$p_dir="D:/43895" ;
print $p_dir;
opendir(DIR, "$p_dir") or die "cant open directory: $!\n";
while(defined($folder = readdir(DIR))) {
if (length $folder > 5)
{
print $folder; }
if (substr($folder,0,8) eq 'PHONELOG') {
&print_out_contents; }
}
closedir(DIR) ;
#------------------------------------------------------------------------------------------
}
sub print_out_contents {
#------------------------------------------------------------------------------------------
my $phonelog = "$p_dir/$folder";
open (P1FILE, "$phonelog") or die "can't open $phonelog: $!";
flock (P1FILE, LOCK_SH) or die "can't lock $phonelog: $!";
while (<P1FILE>)
{
chomp;
@linex = split(/\|/);
&plfields;
&build_days;
}
close (P1FILE);
#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------
sub plfields {
#------------------------------------------------------------------------------------------
$plcallername = $linex[0];
$plcallerphone = $linex[1];
$plcalleremail = $linex[2];
$plsentdate = $linex[3];
$plsentdate_ccyy = substr($plsentdate,0,4) ;
$plsentdate_yy = substr($plsentdate,2,2) ;
$plsentdate_mm = substr($plsentdate,4,2) ;
$plsentdate_dd = substr($plsentdate,6,2) ;
$pltime = $linex[4];
$plfilebase = $linex[5];
$pltext = $linex[6];
($plfilebase_type,$plfilebase_num,$plfilebase_name) = split (/\_/,
$plfilebase);
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/