use File::Find;
use strict;
#Create a list of files
my @file_list = ();
my $dir = shift(@ARGV);
find (\&find_files, $dir);
my $file_count = @file_list;
my $cur_file_num = 1;
my $file_name = "";
my $OFH;
foreach $file_name (@file_list){
open my $IFH, "<", $file_name
or die "Could not open input file: $file_name\n";
print "Working on $cur_file_num/$file_count: $file_name\n";
#Create the directory that will hold the results
$file_name =~ /.*\/(.*).blg$/;
my $directory_name = $dir . "\\" . $1;
print "Creating directory: $directory_name\n";
mkdir $directory_name;
#Set up some variables
my $line = "";
my $output_file_name = "";
my $int_file_count = 0;
my $reading_data = 0;
my $data_format = "";
my $bytes = 0;
my $data_struct = 0;
#Now run throught the file and split it up
while (<$IFH>){
$line = $_;
if ($reading_data){
$reading_data = 0;
$/ = "\n";
}
if ($line =~ /FileName: (.*)/){
chomp($output_file_name = $1);
$int_file_count++;
print "\t\t\tOpening: " . $directory_name . "\\" . $output_file_name . "\n";
open $OFH, ">", $directory_name . "\\" . $output_file_name
or die "Could not open output file: $output_file_name\n$!";
print "\tFound: $output_file_name\n";
}
if ($line =~ /DataStruct: (.*)/){
$data_struct = $1;
}
if ($line =~ /DataForm:/){
$data_format = substr $_, 9; # remove header
$data_format =~ tr/,//d; # remove commas
$bytes = ( () = $data_format =~ /D/g) * 8; # Count the doubles floats
$bytes += ( () = $data_format =~ /L/g) * 4; # Count the longs
$bytes += ( () = $data_format =~ /S/g) * 2; # Count the shorts
$bytes += ( () = $data_format =~ /F/g) * 4; # Count the single floats
$bytes *= $data_struct; # Multiply by the number of records
print "\t\tData size: $bytes\n";
}
if ($line =~ /NextFile:/){
$/ = \$bytes; # change how much data is read in at one time
$reading_data = 1;
}
print $OFH $line;
}
}
###################################################
#find_file subroutine called by "find"
sub find_files {
if ($_ =~ /.*\.blg/){
push @file_list, $File::Find::name;
# print "$File::Find::name\n";
}
}
####
47 open $OFH, ">", $directory_name . "\\" . $output_file_name
or die "Could not open output file: $output_file_name\n$!";
####
open $OFH, ">:raw", $directory_name . "\\" . $output_file_name