Solved

How can I change the date and time attribute to the current date and time on a file after copying it with cffile

Posted on 2007-11-13
9
189 Views
Last Modified: 2013-12-24
When copying a file with CFFILE, the original date and time needs to be changed to the current date.

<cffile action="copy" source="sourcefile_001.jpg" destination="c:\destination\destfile_001.jpg">

Is there a way to do this with cffile or any other cf8 tag, and using the example with cffile above?

0
Comment
Question by:Janrow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 20276886
That should happen automatically.
0
 

Author Comment

by:Janrow
ID: 20276920
> That should happen automatically.

Perhaps it should, but it does not. Never has. Using the cffile tag and options given in my example, the source file, once copied, always retains the original date.

I am copying the file from drive d (outside the webroot) to virtual website directory on drive c.

I'm using cf8 standard on win2003 r2 32bit server.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20276960
Afaik it does not change the timestamp of the file.  One way to change the date is to use java

<cfset fullPathToFile = "c:\pathToYourFile.jpg">
<cfset javaFileObject = createObject("java", "java.io.File").init(fullPathToFile)>
<cfset newDate = createObject("java", "java.util.Date").init()>
<cfset javaFileObject.setLastModified(newDate.getTime())>

0
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 52

Expert Comment

by:_agx_
ID: 20276982
Though if you want to be thorough you should catch any exceptions and check the returned value to verify the value really was changed.

<cftry>
      <cfset fullPathToFile = "c:\pathToYourFile.jpg">
      <cfset javaFileObject = createObject("java", "java.io.File").init(fullPathToFile)>
      <cfset newDate = createObject("java", "java.util.Date").init()>
      <cfset wasChanged = javaFileObject.setLastModified(newDate.getTime())>
      <cfcatch type="java.lang.SecurityException">
            <cfset wasChanged = false >
      </cfcatch>
</cftry>

<cfdump var="wasChanged = #wasChanged#">
0
 

Author Comment

by:Janrow
ID: 20277099
Hmm. I was hoping cffile has a parameter to set the date/time. I'm not much up to JavaScript, but I gave it a try, with your code and my variables for the fullpathtofile and got this error message:

Just in time compilation error
Invalid parser construct found on line 95 at position 61. ColdFusion was looking at the following text:
.
Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was a CFSET tag occupying document position (95:1) to (95:6).

What might be wrong? Here's my cffile, with your code following it:

<cffile action="copy" source="#filename#" destination="c:\download\#newFilename#">

<cfset fullPathToFile = "c:\download\#newFilename#">
<cfset javaFileObject = createObject("java", "java.io.File").init(fullPathToFile)>
<cfset newDate = createObject("java", "java.util.Date").init()>
<cfset javaFileObject.setLastModified(newDate.getTime())>

#newFilename# is the file to be copied and downloaded from the destination folder.

Jan



0
 
LVL 52

Expert Comment

by:_agx_
ID: 20277116
The java code snippet you posted works fine. The error must be in some other part of the code.

But I realized there's a much easier way since you're using CF8.  Its a function.

FileSetLastModified
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_18.html#5177996
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 20277129
Here is the simpler CF8 example

<cfset FileSetLastModified( "c:\download\#newFilename#", Now()) >
0
 

Author Comment

by:Janrow
ID: 20282733
Yes, that works, and much simpler. Thanks!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20282771
Yes, the more complicated example would be for MX7.  CF8 has some nice improvements over MX7!
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question