Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    London
    Posts
    76

    Unanswered: Find files by modified date

    Hi,

    I am trying to construct a Perl script that would only find files in a folder if the modified date is equal to todays date. I am finding it difficult to find some information on this on the web! any help would be much appreciated...

    I am running Perl on a windows platform. The aim of the script is to find files with "article" in the filename where the modified date is equal to the current date and report the contents of the file in an excel spreadsheet. I can create the spreadsheet and find files with article in the name but having trouble limiting the files where the modified date is equal to the current date.

  2. #2
    Join Date
    Feb 2006
    Posts
    56
    you need to use the stat function or the -M file test operator to get the modified date.

    http://perldoc.perl.org/functions/-X.html

    Code:
    chdir('yourdir');
    opendir(DIR ,'.');
    my @articles = grep {/article/ && (-M)  <= 1} DIR;
    close(DIR);
    now you should have a list of the files you are looking for in @articles

  3. #3
    Join Date
    Feb 2004
    Location
    London
    Posts
    76
    Thanks for this but it does not work for me! any other suggestions?

  4. #4
    Join Date
    Feb 2006
    Posts
    56
    sorry, this line:

    my @articles = grep {/article/ && (-M) <= 1} DIR;

    should be:

    my @articles = grep {/article/ && (-M) <= 1} readdir DIR;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •