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
180 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

13 Experts available now in Live!

Get 1:1 Help Now