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
182 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
  • 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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 21
Configure IIS to process JSON 10 74
SSL sertificate 5 58
setup wamp server for first time 2 43
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now