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

i want to parse through files which lies between dates given as input by the user. I am able to access all files in the path metioned by user and i am trying to find the mtime of the files for the purpose . i am also able to get all the files mtime date in dd/mm/yyyy format.i am also taking dates as input from user in dd/mm/yyyy format . what my query is that am i correct in finding the mtime of the files for the purpose . another one is that how do i get the files whose creation dates lies between the dates input by the user .

Replies are listed 'Best First'.
Re: files & dates
by Limbic~Region (Chancellor) on Jan 07, 2005 at 16:08 UTC
    rjsaulakh,
    First, you should check out perldoc -f stat. Next, you should know that depending on the OS, it may be impossible to get the actual create date. Next, you will make your job easier if instead of using dates in the format of DD/MM/YYYY, you use epoch timestamps. You can easily convert using a simple regex and Time::Local. My advice would be to use a time of 00:00:01 for the start range and 23:59:59 for the end range. It is then a simple matter of seeing if one number (from stat) is between two other numbers.

    Cheers - L~R

    Update: I originally assumed that the list of candidate files was already known and you would just need to determine if each one in succession met the criteria. If that isn't the case and you need to find the files take a look at File::Find, File::Find::Rule, and File::Finder coupled with the general approach in this post.

Re: files & dates
by friedo (Prior) on Jan 07, 2005 at 16:09 UTC
    I would use Date::Manip or one of the other Date modules to convert your input dates into epoch times. Then, simply do a numerical comparison to see if the mtime for each file is between your bounds.
      i have gone through the Date::Manip but was unable to find what can convert my input date in format of dd/mm/yyyy into epoch
      thx for ur help . i am able to get the mtime of the files . i am taking input from user in dd/mm/yyyy format and i am using ParseDateString($string1) to get the epoch time but the problem is that the output in this case is 2005090100:00:00 while the epoch for the same file is 1105215157. do i need to use a different function to get input dates into epoch secs.
Re: files & dates
by jZed (Prior) on Jan 07, 2005 at 16:21 UTC
    Any way you can use yyyy/mm/dd format? It's much more universally legible and you can order the dates with simple sorting rather than needing to convert dates to compare them. For example:

    perl -e 'print "ok" if "2004-05-11" lt "2004-06-11"'

      thx for ur response but i need to take two dates as input from user and compare whether the modified date of the files lies between the two dates taken as input and then take a ll the files matching in an array for later processing