matze77 has asked for the wisdom of the Perl Monks concerning the following question:

I want to move files depending on their date, from a maildir in an archive based on the year.
example:
~/Maildir/.MailingList/cur Here are all Mails from years 2005 till 2008 I want to move the Mails from here to Maildir.subfolder 2008: ~/Maildir/MailingList.2008/cur$ for each mail X in current dir do if date of file contains "2008" M X { mv X ~/Maildir/MailingList.2008/cur$ } }
I dont know where to start,
which functions to use in Perl i searched for "moving files" but didnt find exactly what i need in this case.
If i missed a thread please show it to me ...
Maybe you could post some code sniplets?
which could help me to adopt it to my "problem", read through the needed sections of docs.
Thanks for any help in advance

Replies are listed 'Best First'.
Re: moving files in a dir (Maildir) depending on Date
by oko1 (Deacon) on Nov 26, 2008 at 23:41 UTC
    I dont know where to start, which functions to use in pearl i searched for "moving files" but didnt find exactly what i need in this case.

    <pedantic>It's "Perl" for the language, "perl" for the executable name. Not "PERL", and certainly not "pearl".</pedantic>

    As to not knowing where to start - I suggest figuring out the steps that you need to take to make this happen, and then creating those steps out of the available functions. Experienced programmers, of course, know what all (or most) of the functions are and design their programs out of those "building blocks"; since you appear to be just starting out, you'll need to run a few cycles of this before you succeed.

    Here's an idea of how you might approach this (this is based on what you've already said; there are better approaches):

    [pseudocode] Loop over the list of files in the source directory Read each file's date If date contains 2008 Move file to target directory End if End loop

    That's half the job done for you. All you have to do is read "perldoc perlfunc" and fill in the blanks.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
      Hi Monks!
      You guessed it, i got another Mail related "problem":

      If i want to sort some mails depending on the message id,
      should i grep for the message id through all (Maildir) files or would it be better to use something like:
      Email::abstract
      get_header
      http://search.cpan.org/~rjbs/Email-Abstract-2.134/lib/Email/Abstract.pm#get_header

      The same would be for the header: "LIST-ID" field of some mailing lists,
      that are unfortunately lurking in my inbox cause i adjusted the filter later?

      I found a maybe related thread but i am not sure if i could use this, since it seems for mbox, but i dont understand it, completely to be honest:

      Reaping messages by Message-ID

      What about performance? is the cpan module ressource friendlier or the standard grep method.

      Or am i completely on the wrong path and you suggest something different.
      Some code which i could adjust to my needs would be appreciated.
      Thanks for your patience
Re: moving files in a dir (Maildir) depending on Date
by afresh1 (Hermit) on Nov 27, 2008 at 04:06 UTC

    As has been said, the supersearch should have answered your question. But, I think you will want to look at File::Copy and Email::Date, they helped me when I did this.

    l8rZ,
    --
    andrew
      First. Thanks @all for your replies and tips, seems i have to dig in a little deeper, Email::Date pushes me into the right direction.
      I come back after i learned more.
      Thank you!.

      Update:
      #!/usr/bin/perl -w use strict; foreach(<*>) { if (-M $_ > 660) { use File::Copy;copy("$_","/tmp/testd +ir/") or die "Copy failed: $!";} }
      I changed the requirement to older than 660 days thats close enough for now. Calculating with Dates is for another day.
      Any comments are welcome.
      /Update
Re: moving files in a dir (Maildir) depending on Date
by toolic (Bishop) on Nov 26, 2008 at 22:30 UTC
    You can use Super Search here at the Monastery. I just searched node titles for the string "mov file" and there are links to many examples.

    If you click on the this link, then hit the "Search" button, you will see more links. This should give you some ideas of how to begin.