On Apr 14, 2009, at 1:38 PM, zilore mumba wrote:

> Dear Perl Users,
> In the program below, am trying to put many text files into one. The  
> program creates the directories as desired, moves the files to the  
> directories as per commands and creates an output file.
> But the file created is empty and the error message is indicated as  
> the path specified is not found. Am not sure exactly which line is  
> not correct.
> Help will be appreciated.
> Zilore Mumba
>
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> use POSIX;
> use File::Path;
> use File::Copy;
> #
> my $debug = 0;
> #
> my @now = localtime;
>  my ($day, $mon, $year) = (localtime(time() - 60 * 60 * 24) )  
> [ 3,4,5];
>
>  $year = $year+1900;
>  $mon = $mon+1;
>  open(DAT_OUT, ">datefile.txt");
>  printf DAT_OUT ("%04d%02d%02d\n", $year, $mon,$day);
>  close OUT;
>  open(DAT_OUT, "<datefile.txt");          # we write date in a file  
> so that month is tow-digit
>  my $dat0=<DAT_OUT>;
>  chomp $dat0;
>  close OUT;
>  my $msg_pref = 'msgs';
>  my $ext ='.txt';
>  my $out_file = "$dat0$msg_pref$ext";
>  my $msg_dir = 'Messages';
> if ( ! -d $msg_dir ) {     # Create a directory called Messages
>   print "mkpath $dat0\n" if $debug;
>   mkpath ($msg_dir ) or die "mkpath '$msg_dir' failed: $! ($^E)";
> }
>
> my $cmd01 = "mv msg* $msg_dir";  # Move all messages to directory  
> Messages
> print "doing system ($cmd01)\n" if $debug;
> system ($cmd01);
>  chdir ($msg_dir) or die "cd to '$msg_dir' failed: $! ($^E)";
>           # Change directory to directory Messages
> if ( ! -d $dat0 ) {
>   print "mkpath $dat0\n" if $debug;
>   mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^E)";
>   }         # Create a directory called by yesterday's date
> # Move all files to date_directory
>   my $cmd02 = "mv msg* $dat0";  # Move all messages to date directory
>   print "doing system ($cmd02)\n" if $debug;
>   system ($cmd02);     #But program remains in Messages
> # open output file - in dat0 #
> #
>   print "Creating output file '$out_file'\n" if $debug;
>   open OUT, ">$dat0/$out_file" or die "Create '$out_file: failed $!  
> ($^E)";
>   my @files =();
>   opendir DIR, "$dat0" or die "opendir '$dat0' Failed: $! ($^E)";
>   while (my $file = readdir DIR) {
>     next if $file =~ m/msg*/;
>     print "Adding '$file'\n" if $debug;
>     push(@files,$file);
>   }
>   closedir DIR;
>   #my $cmd03 = "type @files > $out_file";                  # for  
> Windows
>   my $cmd03 = ("/cygdrive/c/progra~1/pcgrads/win32/cat @files >  
> $out_file");
>   print "doing system ($cmd03)\n" if $debug;
>   system ($cmd03);
> #my $cmd04 = "rm msg*";
> #print "doing system ($cmd04)\n" if $debug;
> #system ($cmd04);
> __END__
> #
> my $files = dir() or die "Error doing dir: $!\n";
> foreach (@$files) {
>     # skip lines not starting with d or -
>     if (/^[^d-]/) {
> #         print "Skipping garbage dir line\n" if $debug;
>         next;
>     }
> #  dir listing
> #----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
> #total 52
> #drwx--x---   3 owner    group        1024 Dec 13  1997 .
> #drwxr-xr-x 671 owner    group       49152 Dec 18 14:09 ..
> #-rw-r--r--   1 xyz      httpd        2010 Sep 21 13:31 index.htm
>     my ($size, $file) = (split /\s+/, $_, 9)[4,8];    # get size/ 
> filename
>     next if $file =~ /^\.{1,2}$/;        # skip . and ..
>     # if directory - call directory recurse routine
>     if (/^d/) {
>         ...


What is the /exact/ output of your program?

Do you have Cygwin installed on your system? It is not part of  
ActivePerl, and ActivePerl is not part of Cygwin.

Have you indeed the correct path to Cygwin cat there?

-- 
John W Kennedy
"You can, if you wish, class all science-fiction together; but it is  
about as perceptive as classing the works of Ballantyne, Conrad and W.  
W. Jacobs together as the 'sea-story' and then criticizing _that_."
   -- C. S. Lewis.  "An Experiment in Criticism"



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to