Skip to main content
WolfShade
Legend
September 3, 2020
Answered

java.io.File.lastModified returns 0

  • September 3, 2020
  • 1 reply
  • 829 views

Hello, all,

 

I'm working on some legacy code, and the original developer was manually setting a "last modified" date on documents he worked on.  I learned that there is a programmatic way of doing this, and I'm trying, but the value returned is 0.

 

<!--- I got this from Pete Freitag's blog. --->
<cfset thisFile = CreateObject("java","java.io.File") />
<cfset thisFile.init("" & cgi.script_name & "") />
<cfset lastMod = thisFile.lastModified() />
<cfset lastMod = DateFormat(DateAdd('s',lastMod,"January 1 1970 00:00:00"),"mmmm dd, yyyy") />

 

Last mod is reporting as January 1, 1970, which means that it's 0.  Please advise.

 

V/r,

 

^ _ ^

This topic has been closed for replies.
Correct answer WolfShade

Well, I think I know why it didn't work.  But I found another way of doing it, that I will be using.

<cfset thisFilePath = getCurrentTemplatePath() />
<cfset lastMod = DateFormat(GetFileInfo(thisFilePath).lastmodified,'mmmm dd, yyyy') />

I was hoping to do this in application.cfc, just the once.  The above method has to be put on each page, but I'm okay with that.

 

V/r,

 

^ _ ^

1 reply

WolfShade
WolfShadeAuthorCorrect answer
Legend
September 3, 2020

Well, I think I know why it didn't work.  But I found another way of doing it, that I will be using.

<cfset thisFilePath = getCurrentTemplatePath() />
<cfset lastMod = DateFormat(GetFileInfo(thisFilePath).lastmodified,'mmmm dd, yyyy') />

I was hoping to do this in application.cfc, just the once.  The above method has to be put on each page, but I'm okay with that.

 

V/r,

 

^ _ ^