--- On Tue, 4/14/09, Bill Luebkert <[email protected]> wrote: From: Bill Luebkert <[email protected]> Subject: Re: help concatenation of files To: [email protected] Date: Tuesday, April 14, 2009, 11:05 PM Bill, Thank you very much for the code. The name format for the messages is something like "msg00001234", i.e msg followed by an 8-digit number. The messages are coming continuously and the number is like a serial. The code you sent me creates "Messages" and date directory eg "20090414". It also creates the out_file in "20090414" but the file is empty. And I think the code below (starting from opendir does not work because none of the msg files is moved. In fact the files are not in $msg_dir (which is newly create) but are one directory higher if (! -d $msg_dir) { # Create a directory called Messages print "mkpath $msg_dir\n" if $debug; mkpath ($msg_dir) or die "mkpath '$msg_dir': $! ($^E)"; } opendir DIR, $msg_dir or die "opendir $msg_dir: $! ($^E)"; while ($_ = readdir DIR) { # is there a name format for msg files ? # next if not /???/; next if -d "$msg_dir/$_"; print "rename $_, '$msg_dir/$_'\n"; rename $_, "$msg_dir/$_" or warn "rename '$_' to '$msg_dir': $! ($^E)"; } closedir DIR; # Change directory to directory Messages print "chdir $msg_dir\n" if $debug; chdir $msg_dir or die "chdir '$msg_dir': $! ($^E)"; # 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': $! ($^E)"; } # Move all files to date_directory opendir DIR, '.' or die "opendir '.': $! ($^E)"; while ($_ = readdir DIR) { next if -d $_; print "rename $_, '$dat0/$_'\n"; rename $_, "$msg_dir/$_" or warn "rename '$msg_dir/$_': $! ($^E)"; } closedir DIR; # open output file - in dat0 print "Creating output file '$out_file'\n" if $debug; open OUT, ">>$dat0/$out_file" or die "CreateAp '$out_file: failed $! ($^E)"; opendir DIR, $dat0 or die "opendir '$dat0': $! ($^E)"; while ($_ = readdir DIR) { next if -d $_; next if /^$out_file$/i; print "Adding '$_'\n" if $debug; open IN, "$dat0/$_" or warn "open '$dat0/$_': $! ($^E)"; while (<IN>) { print OUT; } close IN; } closedir DIR; close OUT; __END__
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
