Thank you very much all the very valuable assistance. From the time I got the
code on !*th I have been traveling, so could not acknowledge earlier.
Justin, the script below which you sent me works marvelously, and thanks for
the better directory structure.
Just in case you are able to spend another 5 five minutes for me, at the end of
writing the data in one file, I need to remove the original files. If I try to
unlink the files I could end up deleting the newly created file. I do not want
to mess this wonderful code.
My appreciation to all who spared their time on my problem
Zilore
> use strict;
> use warnings;
> use POSIX;
> use File::Path;
> use File::Copy;
>
> # Variable declaration
> my $debug = 1;
> my $from_dir = "C:/Temp";
> my $top_dir = "C:/Weather";
>
> my ($day, $mon, $year) = ( localtime(time - 86400) )[ 3, 4,
> 5 ];
>
> my $dat0 = sprintf( "%04d%02d%02d", $year + 1900,
> ++$mon, $day );
>
> my $out_file = "$top_dir/$dat0/$dat0.txt";
> print "out_file='$out_file'\n" if
> $debug;
>
> $dat0 = "$top_dir/$dat0";
>
> # Create a directory called by yesterday's date if not
> there
> if ( ! -d $dat0 )
> {
> print "mkpath $dat0\n" if $debug;
>
> mkpath( $dat0 ) or die "mkpath '$dat0'
> failed: $! ($^E)";
> }
>
> # Move all files to date_directory
> opendir my $DIR, $from_dir or die "opendir failed on
> $from_dir: $! ($^E)";
>
> while ( my $item = readdir $DIR )
> {
> next if -d $item;
>
> print "move( '$from_dir/$item',
> '$dat0/$item')\n";
> move( "$from_dir/$item", $dat0) or warn
> "move from $from_dir/$item
> to $dat0 failed: $! ($^E)";
> }
> closedir $DIR;
>
> # open output file - in dat0
> print "Creating output file
> '$out_file'\n" if $debug;
>
> open my $OUT, '>>', $out_file or die
> "Append to '$out_file: failed $! ($^E)";
>
> opendir $DIR, $dat0 or die "opendir on $dat0 failed:
> $! ($^E)";
>
> while ( my $item = readdir $DIR )
> {
> next if -d "$dat0/$item";
> next if "$dat0/$item" =~ /^$out_file$/io;
>
> print "Adding '$dat0/$item'\n" if
> $debug;
>
> open my $IN, '<', "$dat0/$item" or
> warn "open on '$dat0/$item'
> failed: $! ($^E)";
>
> while ( <$IN> )
> {
> print $OUT $_;
> }
> close $IN;
> }
> closedir $DIR;
> close $OUT;
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe:
> http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs