Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Quick Perl Question

Expand Messages
  • Charles K. Clarkson
    ... It should be fairly easy. Look at the File::Copy module, so you don t have to worry about your operating system s special needs. I believe stat will help
    Message 1 of 5 , May 31, 2001
    • 0 Attachment
      David Aldridge <holein5@...> asked:

      : How hard would it be to whip up a PERL script to
      : do a "dir" in a directory then copy the file with
      : the latest date and timestamp to another
      : directory? I was thinking PERL would be best for
      : this but if anyone has any other ideas I would
      : really appreciate it.
      :
      : Thanks for your time,
      : David Aldridge
      : Sr Systems Analyst
      : Convergys Corp
      :

      It should be fairly easy. Look at the
      File::Copy module, so you don't have to worry
      about your operating system's special needs.
      I believe stat will help with the time stamp.

      HTH,
      Charles K. Clarkson


      We receive three educations:
      one from our parents,
      one from our schoolmaster,
      and one from the world.
      The third contradicts all that the first two teach us.
      - Baron de Montesquieu
    • J.E. Cripps
      ... #here s one approach #find the file in source directory with the latest update time (mtime) #!/usr/bin/perl -w use strict; my $src =
      Message 2 of 5 , May 31, 2001
      • 0 Attachment
        > How hard would it be to whip up a PERL script to do a "dir" in a
        > directory then copy the file with the latest date and timestamp to
        > another directory? I was thinking PERL would be best for this but if
        > anyone has any other ideas I would really appreciate it.

        #here's one approach
        #find the file in source directory with the latest update time (mtime)

        #!/usr/bin/perl -w
        use strict;


        my $src = '/path/to/source_directory';
        my $tgt = '/path/to/target_directory';

        #open source directory
        unless (opendir(IN,"$src")) {
        print "couldn't open directory($!)\n";
        exit;
        }
        #list of files in source_directory
        my @files = readdir(IN);
        closedir(IN);

        my %files; #associate file with time of last update
        foreach my $f(@files) {
        $files{$f} = (stat($f))[9];
        }

        #sort to find newest file
        my @timesort = sort { $files{$b} <=> $files{$a} } keys(%files);

        my $newest;
        #print newest file that's not the directory
        foreach my $f(@timesort) {
        if ($f !~ /\./) {
        $newest = $f;
        print "$f\n"; last;
        }
        }


        # that's all folks; to _copy_ $newest look at:

        # system() perldoc perlfunc or
        # or File::Copy perldoc File::Copy


        =head
        #print files and uptdate times
        #this reminded us that . is in @files also
        foreach my $t(@timesort) {
        printf "file %s updated at %s\n", $t,
        scalar localtime($files{$t});
        }

        =cut
      • David Aldridge
        Thank you VERY much! ... From: J.E. Cripps [mailto:cycmn@nyct.net] Sent: Friday, June 01, 2001 12:34 AM To: perl-beginner@yahoogroups.com Subject: Re: [PBML]
        Message 3 of 5 , Jun 1, 2001
        • 0 Attachment
          Thank you VERY much!
          -----Original Message-----
          From: J.E. Cripps [mailto:cycmn@...]
          Sent: Friday, June 01, 2001 12:34 AM
          To: perl-beginner@yahoogroups.com
          Subject: Re: [PBML] Quick Perl Question


          > How hard would it be to whip up a PERL script to do a "dir" in a
          > directory then copy the file with the latest date and timestamp to
          > another directory? I was thinking PERL would be best for this but if
          > anyone has any other ideas I would really appreciate it.

          #here's one approach
          #find the file in source directory with the latest update time (mtime)

          #!/usr/bin/perl -w
          use strict;


          my $src  = '/path/to/source_directory';
          my $tgt =  '/path/to/target_directory';

                                 #open source directory
          unless (opendir(IN,"$src")) {
                print "couldn't open directory($!)\n";
                exit;
          }
                                       #list of files in source_directory
          my @files =  readdir(IN);
          closedir(IN);

          my %files;                 #associate file with time of last update
          foreach my $f(@files) {
                $files{$f} = (stat($f))[9];
          }

                                 #sort to find newest file
          my @timesort = sort { $files{$b} <=> $files{$a} } keys(%files);

          my $newest;
                                       #print newest file that's not the directory
          foreach my $f(@timesort) {
                if ($f !~ /\./) {
                $newest = $f;
                print "$f\n"; last;
                   }
          }


          # that's all folks; to _copy_  $newest look at:

          #  system()     perldoc perlfunc            or
          # or File::Copy    perldoc File::Copy


          =head
                                 #print files and uptdate times
                                       #this  reminded us  that . is in @files also
          foreach my $t(@timesort) {
                  printf "file %s updated at %s\n", $t,
                      scalar localtime($files{$t});
          }

          =cut




          Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
        Your message has been successfully submitted and would be delivered to recipients shortly.