Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
192 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 2000 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
What You Need to Know when Searching for a Webhost Provider
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

719 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