0

如果中央文件夹中的文件较新,我想更新文件。

这是我到目前为止所拥有的,但随着月份的变化它似乎不起作用 - 几天和几分钟都可以正常工作。

<cfdirectory action="list" directory="#baseViewStackDir#" filter="#viewStackFileName#" name="base_fileInfo">
<!--- end --->
<cfset myViewStackDir = ExpandPath('/designer/app') />
<cfdirectory action="list" directory="#myViewStackDir#" filter="#viewStackFileName#" name="target_fileInfo">
<cfset copy = false />
<cfif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"yyyy") GT 0 >
  <cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"m") GT 0>
  <cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"d") GT 0>
  <cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"h") GT 0>
  <cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"n") GT 0>
  <cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"s") GT 0>
  <cfset copy = true />
</cfif>
<cfif copy EQ true>
  <cffile action="copy" source="#baseViewStackDir##viewStackFileName#" destination="#myViewStackDir#"/>
</cfif>
<script type="text/javascript">
  console.log("swf updated=<cfoutput>#copy# #base_fileInfo.DATELASTMODIFIED# - #target_fileInfo.DATELASTMODIFIED# ....#DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,'m')#</cfoutput>");
</script>

请问谁能发现我的错误?

4

1 回答 1

1

正如彼得和我在评论中提到的那样,您可以将整个脚本更改为

<cfif base_fileInfo.DateLastModified GT target_fileInfo.DateLastModified>
  <cffile action="copy" source="#baseViewStackDir##viewStackFileName#" destination="#myViewStackDir#"/>
</cfif>

<script type="text/javascript">
console.log("swf updated=<cfoutput>#copy# #base_fileInfo.DATELASTMODIFIED# - #target_fileInfo.DATELASTMODIFIED# ....#DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,'m')#</cfoutput>");
</script>

如果您尝试自动版本化您的 js/css 文件,您可以使用类似这样的方法来读取文件的修改日期并将该日期附加到 js/css url

<cffunction Name="autoversion" access="public" returntype="string" output="false">
  <cfargument Name="filepath" type="string" required="yes">
  <cfset var fileDate = createObject("java","java.util.Date").init(createObject("java","java.io.File").init('C:\railo\webapps\railo\website\bootstrap\js'&Replace(arguments.filepath, '/', '\', 'ALL')).lastModified())>
  <cfreturn 'https://www.mydomain.com/'&arguments.filepath&'?d='&DateFormat(fileDate, 'mmddyyyy')&TimeFormat(fileDate, 'hh')>
</cffunction>

<cfset autoversion('/bootstrap.js')>
于 2013-09-04T12:26:12.433 回答