Could you try running this and let me know if it functions properly. I combined a few subs and eliminated the delete sub. But I wasn't sure how to test it.

#!/usr/bin/perl use strict; use warnings; use File::Copy; sub copy_from_root { my $ftp_dir = shift; opendir my $dir, $ftp_dir or die "Cannot open $ftp_dir: $!"; my %short_names; for my $file_name (grep /\.(?:txt|doc|mpd|mta)$/i, readdir $dir) { my $daym = (localtime)[3]; my @dirs = ("c:/afis3too/$daym", 'c:/scripts/attempt', 'c:/rep +orts'); print $file_name; chomp $file_name; my $source = "$ftp_dir/$file_name"; $short_names{sprintf('%.6s.bat', lc $file_name)}++; if ($file_name =~ /^(?:afinv|csinv|sfinv)/i) { s/\.mta$/\.mpd/i; push @dirs, 'c:/invoice'; } elsif ($file_name =~ /\.doc$/i) { s/doc$/txt/ig; } elsif ($file_name =~ /\.mta$/i) { s/mta$/mpd/ig; } foreach my $dir (@dirs){ copy($source, "$dir/$file_name") or die "Cannot copy $dir/$file_name: $!"; } unlink $source or die "Cannot unlink $source: $!"; } return keys %short_names; } sub batch_files { my $batch_dir = shift; opendir my $dir, $batch_dir or die "Cannot open $batch_dir: $!"; my @files = grep /\.bat$/i, readdir $dir; return \@files; } sub run_the_batches { my ($short_names, $batch_files, $dir) = @_; my @matches; foreach my $short_name (@$short_names){ push @matches, grep /$short_name$/i, @$batch_files; print "Working...\n"; } system("$dir/$_") for @matches; } my $ftp_dir = 'c:/ftproot'; my $report_dir = 'c:/reports'; print "\n\n\n"; print " Robco Inc. Presents : \n\n\n"; print " The NEW, AMAZING, INCREDIBLE ....\n\n\n"; print " Robco Document Rotisserie!!!!!\n\n\n"; print "Just RENDER it, THEN don't REMEMBER it!!!!!\n\n"; print " It's just that easy.\n\n\n\n\n"; while (1) { print localtime, "\n"; print "sleeping .... ZzZzZzZzZz......\n"; sleep (10); print "OK! OK! .... I'm awake! .... I'm awake\n"; my $short_names = copy_from_root($ftp_dir); my $batch_files = batch_files($report_dir); run_the_batches($short_names, $batch_files, $report_dir); }

As mentioned above, I am unsure how to test all my changes. I'm sure there's a glitch or two.


HTH,
Charles K. Clarkson

In reply to Re: Document maintenance script by CharlesClarkson
in thread Document maintenance script by blacksmith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.