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

Get all files in directory that are more than 7 days old

Expand Messages
  • Priss
    Hiya, Is there a way to get those files in a directory that are more than 7 days old? (last modified is more than a week ago) Many thanks in advance... Priss
    Message 1 of 8 , Aug 31, 2002
    • 0 Attachment
      Hiya,

      Is there a way to get those files in a directory that
      are more than 7 days old? (last modified is more than
      a week ago)

      Many thanks in advance...

      Priss

      __________________________________________________
      Do You Yahoo!?
      Everything you'll ever need on one web page
      from News and Sport to Email and Music Charts
      http://uk.my.yahoo.com
    • Franki
      well, This is untested, but I think it s in the right direction. you will have to play with the value of $time_to_keep_files as I can t remember the format I
      Message 2 of 8 , Aug 31, 2002
      • 0 Attachment
        well,

        This is untested, but I think it's in the right direction.

        you will have to play with the value of $time_to_keep_files as I can't
        remember the format
        I think 1 is like 24 hours..
        ################################
        my $directory_path = '/some/directory/somewhere';
        my $time_to_keep_files = 7;

        opendir (DH, "$directory_path") or die "can't open $directory_path $!";
        my @files = grep(/\.[0-9]/,readdir(DH));
        closedir (DH);

        foreach my $path_and_file (@files)
        {
        if (-M "$path_and_file" > "$time_to_keep_files")
        {
        unlink("$path_and_file");
        }
        }
        ################################
        So this should delete all files older then 7 days (I think.)

        Hope thats of some help,
        if its wrong I hope you guys will tell me why. :-)

        rgds

        Frank

        -----Original Message-----
        From: Priss [mailto:priss_uk_2000@...]
        Sent: Saturday, 31 August 2002 6:15 PM
        To: perl-beginner@yahoogroups.com
        Subject: [PBML] Get all files in directory that are more than 7 days old


        Hiya,

        Is there a way to get those files in a directory that
        are more than 7 days old? (last modified is more than
        a week ago)

        Many thanks in advance...

        Priss

        __________________________________________________
        Do You Yahoo!?
        Everything you'll ever need on one web page
        from News and Sport to Email and Music Charts
        http://uk.my.yahoo.com


        Unsubscribing info is here:
        http://help.yahoo.com/help/us/groups/groups-32.html

        Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      • Priss
        Thank you for pointing me in the right direction! For some reason, below script gives error: Use of uninitialized value at ./test.pl line 11. 1
        Message 3 of 8 , Aug 31, 2002
        • 0 Attachment
          Thank you for pointing me in the right direction! For
          some reason, below script gives error:

          "Use of uninitialized value at ./test.pl line 11."

          1 #!/usr/bin/perl -w
          2
          3 $dir = "/home/priss";
          4 $days = 7;
          5
          6 opendir (TXT, $dir) or die "Can't open
          direcotry: $!\n";
          7 @files = grep (/\-txt$/,readdir (TXT));
          8 closedir TXT;
          9
          10 foreach $file (@files) {
          11 if (-M $file > $days)
          12 { print "$file\n"; }
          13 }

          I can't see what wrong with it...

          Thanks.

          Priss

          --- Franki <frankieh@...> wrote: > well,
          >
          > This is untested, but I think it's in the right
          > direction.
          >
          > you will have to play with the value of
          > $time_to_keep_files as I can't
          > remember the format
          > I think 1 is like 24 hours..
          > ################################
          > my $directory_path = '/some/directory/somewhere';
          > my $time_to_keep_files = 7;
          >
          > opendir (DH, "$directory_path") or die "can't open
          > $directory_path $!";
          > my @files = grep(/\.[0-9]/,readdir(DH));
          > closedir (DH);
          >
          > foreach my $path_and_file (@files)
          > {
          > if (-M "$path_and_file" >
          > "$time_to_keep_files")
          > {
          > unlink("$path_and_file");
          > }
          > }
          > ################################
          > So this should delete all files older then 7 days (I
          > think.)
          >
          > Hope thats of some help,
          > if its wrong I hope you guys will tell me why. :-)
          >
          > rgds
          >
          > Frank


          __________________________________________________
          Do You Yahoo!?
          Everything you'll ever need on one web page
          from News and Sport to Email and Music Charts
          http://uk.my.yahoo.com
        • Charles K. Clarkson
          ... Did you test to see if anything was in @files after the grep? ... print $_ n foreach @files; # for testing ... Shouldn t that be testing for the full
          Message 4 of 8 , Aug 31, 2002
          • 0 Attachment
            Priss [mailto:priss_uk_2000@...] wrote:
            :
            : Thank you for pointing me in the right direction! For
            : some reason, below script gives error:
            :
            : "Use of uninitialized value at ./test.pl line 11."

            Did you test to see if anything was in @files
            after the grep?

            : 1 #!/usr/bin/perl -w
            : 2
            : 3 $dir = "/home/priss";
            : 4 $days = 7;
            : 5
            : 6 opendir (TXT, $dir) or die "Can't open
            : direcotry: $!\n";
            : 7 @files = grep (/\-txt$/,readdir (TXT));
            : 8 closedir TXT;

            print "$_\n" foreach @files; # for testing

            : 9
            : 10 foreach $file (@files) {
            : 11 if (-M $file > $days)

            Shouldn't that be testing for the full path
            ("$dir/$file") to the file?

            : 12 { print "$file\n"; }
            : 13 }

            HTH,

            Charles K. Clarkson
            --
            Head Bottle Washer,
            Clarkson Energy Homes, Inc.
            Small commercial and residential rehabilitation specialists.
            254 968-8328

            CJ Web Work - Solutions for Real Estate Investors.
            972 216-4952

            CJ Web Hosting - Lookout; We have one whole paying customer!
            254 968-8328
          • Priss
            Thanks Charles, think I got a bit further :-) ... Yes, it does print out all the txt files. ... For some reason, it didn t like: if (-M $dir/$file $days) It
            Message 5 of 8 , Aug 31, 2002
            • 0 Attachment
              Thanks Charles, think I got a bit further :-)

              > Did you test to see if anything was in @files
              > after the grep?

              Yes, it does print out all the txt files.

              > : 9
              > : 10 foreach $file (@files) {
              > : 11 if (-M $file > $days)
              >
              > Shouldn't that be testing for the full path
              > ("$dir/$file") to the file?

              For some reason, it didn't like:

              if (-M $dir/$file > $days)

              It gives error of:

              Argument "one-txt" isn't numeric in divide at
              ./test.pl line 11.
              Argument "/home/priss" isn't numeric in divide at
              ./test.pl line 11.
              Illegal division by zero at ./test.pl line 11.

              Before the foreach loop, how can I define $file is in
              $dir/$_ first? (If you see what I mean?) I think
              this may be the problem, tell me if I am wrong...

              Thanks...

              Priss

              __________________________________________________
              Do You Yahoo!?
              Everything you'll ever need on one web page
              from News and Sport to Email and Music Charts
              http://uk.my.yahoo.com
            • Priss
              Got it working by changing couple of lines to: $dir = /home/priss/ ; if (-M $dir.$file $days) It seems to work! :) Priss ... Charles, think I got a bit
              Message 6 of 8 , Aug 31, 2002
              • 0 Attachment
                Got it working by changing couple of lines to:

                $dir = "/home/priss/";
                if (-M $dir.$file > $days)

                It seems to work! :)

                Priss
                --- Priss <priss_uk_2000@...> wrote: > Thanks
                Charles, think I got a bit further :-)
                >
                > > Did you test to see if anything was in @files
                > > after the grep?
                >
                > Yes, it does print out all the txt files.
                >
                > > : 9
                > > : 10 foreach $file (@files) {
                > > : 11 if (-M $file > $days)
                > >
                > > Shouldn't that be testing for the full path
                > > ("$dir/$file") to the file?
                >
                > For some reason, it didn't like:
                >
                > if (-M $dir/$file > $days)
                >
                > It gives error of:
                >
                > Argument "one-txt" isn't numeric in divide at
                > ./test.pl line 11.
                > Argument "/home/priss" isn't numeric in divide at
                > ./test.pl line 11.
                > Illegal division by zero at ./test.pl line 11.
                >
                > Before the foreach loop, how can I define $file is
                > in
                > $dir/$_ first? (If you see what I mean?) I think
                > this may be the problem, tell me if I am wrong...
                >
                > Thanks...
                >
                > Priss
                >
                > __________________________________________________
                > Do You Yahoo!?
                > Everything you'll ever need on one web page
                > from News and Sport to Email and Music Charts
                > http://uk.my.yahoo.com
                >
                > ------------------------ Yahoo! Groups Sponsor
                >
                > Unsubscribing info is here:
                > http://help.yahoo.com/help/us/groups/groups-32.html
                >
                > Your use of Yahoo! Groups is subject to
                > http://docs.yahoo.com/info/terms/
                >
                >

                __________________________________________________
                Do You Yahoo!?
                Everything you'll ever need on one web page
                from News and Sport to Email and Music Charts
                http://uk.my.yahoo.com
              • Jeff 'japhy' Pinyan
                ... There s a big difference between $dir/$file and $dir/$file One is a string of $dir, / , and $file. The other is the division of the value of $dir by
                Message 7 of 8 , Aug 31, 2002
                • 0 Attachment
                  On Aug 31, Priss said:

                  >> Shouldn't that be testing for the full path
                  >> ("$dir/$file") to the file?
                  >
                  >For some reason, it didn't like:
                  >
                  >if (-M $dir/$file > $days)

                  There's a big difference between

                  "$dir/$file"

                  and

                  $dir/$file

                  One is a string of $dir, "/", and $file. The other is the division of the
                  value of $dir by the value of $file.

                  --
                  Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
                  RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
                  ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
                  <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
                  [ I'm looking for programming work. If you like my work, let me know. ]
                • Nathan.Jeffrey@dhs.vic.gov.au
                  Well, you could do with a Unix find command... find . -mtime +7 Or, in perl, you could do it... perl -e print -M /etc/passwd The -M file test operator
                  Message 8 of 8 , Sep 1, 2002
                  • 0 Attachment
                    Well, you could do with a Unix find command...

                    find . -mtime +7

                    Or, in perl, you could do it...

                    perl -e 'print -M "/etc/passwd"'

                    The '-M' file test operator returns the number of days (to 13 decimal
                    places, in 5.8.0) since the file was modified. See also '-A' and '-C'.

                    N





                    Priss <priss_uk_2000@...>
                    31/08/2002 08:14 PM
                    Please respond to perl-beginner


                    To: perl-beginner@yahoogroups.com
                    cc:
                    Subject: [PBML] Get all files in directory that are more than 7 days old


                    Hiya,

                    Is there a way to get those files in a directory that
                    are more than 7 days old? (last modified is more than
                    a week ago)

                    Many thanks in advance...

                    Priss

                    __________________________________________________
                    Do You Yahoo!?
                    Everything you'll ever need on one web page
                    from News and Sport to Email and Music Charts
                    http://uk.my.yahoo.com


                    Unsubscribing info is here:
                    http://help.yahoo.com/help/us/groups/groups-32.html

                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/







                    _________________________________________________________________________________

                    This email contains confidential information intended only for the person named above and may be subject to legal privilege. If you are not the intended recipient, any disclosure, copying or use of this information is prohibited. The Department provides no guarantee that this communication is free of virus or that it has not been intercepted or interfered with. If you have received this email in error or have any other concerns regarding its transmission, please notify Postmaster@...
                    _________________________________________________________________________________
                  Your message has been successfully submitted and would be delivered to recipients shortly.