3 Replies Latest reply: Mar 3, 2009 2:22 PM by BenChase
BenChase Level 1 Level 1 (10 points)
I have a script that I want to use to check the number of days old a file is. 2 things happen, I check to make sure the file is more then 5 days old and then I set the number of days old as a variable.

This is what I have but my problem is that it doesn't work if the file's mod date is in a different month.

How can I get this to work taking into account month and probably year?

property NumDays : 0 --Number of Days to check
property ProofsOutFolder : "my:location"


set dateNow to current date

tell application "Finder"
set theFiles to every file of folder ProofsOutFolder
repeat with aFile in theFiles
set fileModDate to modification date of aFile
if ((day of dateNow) - (day of fileModDate)) ≥ NumDays then
set DaysOut to ((day of dateNow) - (day of fileModDate))
  • Camelot Level 8 Level 8 (46,120 points)
    The problem is that you're comparing the 'day' of each element, so you will have that problem.

    Instead, consider the entire date:

    tell application "Finder"
      set theFiles to every file of folder ProofsOutFolder
      repeat with aFile in theFiles
        set fileModDate to modification date of aFile
        set DaysOut to ((current date) - (fileModDate)) div days
        if DaysOut ≥ NumDays then
          display dialog "File is " & DaysOut & " days old."
        end if
      end repeat
    end tell
  • xnav Level 5 Level 5 (6,630 points)
    See timeDifference examples [here|http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScri ptLangGuide/reference/ASLRclasses.html#//appleref/doc/uid/TP40000983-CH1g-BBCGECID].
  • BenChase Level 1 Level 1 (10 points)
    Thanks guys!!