PDA

View Full Version : Delete OLD files


markstaylor
08-11-2007, 09:09 PM
I am trying to compare the date of a list of files (each file) to the current date. If it's older than 60 day's I want to delet it. I can't figure out how to compare the dates. I can get the CreationDateISO but it has the time, and the File.Attributes Date is different. I'm comfused

jassing
05-27-2009, 12:21 AM
2 years too late... but

function File.Age( cFile )
local nNow = String.Replace(System.GetDate(DATE_FMT_ISO), "-", "", false);
local cDate = String.Replace(File.GetAttributes(cFile).CreationD ateISO,"-","",false);
local nT = String.Find(cDate, "t", 1, false)
local nFile = String.ToNumber( String.Left(cDate,nT-1) )

return Math.Abs(nNow-nFile)
end

jassing
05-27-2009, 10:55 AM
Silly me -- this really isn't right at all!
This doesn't take into account that days only go to 30 and months only to 12.... Late night yesterday... disregard that function....

jassing
05-28-2009, 02:00 PM
Here's a version that will probably work for most... You can take it from here to be more specific to each month's days.

function File.AgeInDays( cFile )
-- This uses averages of:
-- 365.25 days per year
-- 30.44 days per month (365.24 days per year/12 months)
-- Becuase of this; it's not 100% accurate.

local cNow = String.Replace(System.GetDate(DATE_FMT_ISO), "-", "", false);
local cDate = String.Replace(File.GetAttributes(cFile).WriteDate ISO,"-","",false);
local nT = String.Find(cDate, "t", 1, false)
local cFile = String.Left(cDate,nT-1)

local nFileY = String.Left(cFile,4)
local nFileM = String.Mid(cFile,5,2)
local nFileD = String.Right(cFile,2)

local nNowY = String.Left(cNow,4)
local nNowM = String.Mid(cNow,5,2)
local nNowD = String.Right(cNow,2)

local nFileDays = Math.Ceil( (nFileY*365.25) + (nFileM * 30.44) + nFileD )
local nNowDays = Math.Ceil( (nNowY*365.25) + (nNowM * 30.44) + nNowD )

return Math.Abs( nNowDays - nFileDays )
end