If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Find files by modified date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-06, 14:53
dsehmby dsehmby is offline
Registered User
 
Join Date: Feb 2004
Location: London
Posts: 76
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.
Reply With Quote
  #2 (permalink)  
Old 12-12-06, 18:19
KevinADC KevinADC is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 12-13-06, 04:45
dsehmby dsehmby is offline
Registered User
 
Join Date: Feb 2004
Location: London
Posts: 76
Thanks for this but it does not work for me! any other suggestions?
Reply With Quote
  #4 (permalink)  
Old 12-13-06, 17:16
KevinADC KevinADC is offline
Registered User
 
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;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On