Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out when file was created in ColdFusion

I have found a function which returns file info: GetFileInfo()

It returns following data:

  • Name: name of the file
  • Path: absolute path of the file
  • Parent: path to the file’s parent directory
  • Type: either "directory" or "file"
  • Size: file size in bytes
  • Lastmodified: datetime when it was the file was most recently modified
  • canRead: whether the file can be rea
  • canWrite: whether the file has write permission
  • isHidden: whether the file is a hidden

But this data does not show when the file was actually created. How to find it out?

like image 935
Maxim Avatar asked Dec 16 '16 09:12

Maxim


People also ask

How do you find the current date in ColdFusion?

Use the Now() function to obtain the current date and time from the server. Continuing onward, we can customize the date format even more by specifying a mask in the DateFormat() function. The TimeFormat() function is similar to DateFormat(), except, of course, that it returns the time.

How do I change the date format in ColdFusion?

Hence, dateformat(now(), "mm-D-yyyy") is the same as dateformat(now(), "mm-d-yyyy") when flag is set to true. By default Capital D is used to specify Day of the year. See example below. ColdFusion (2018 release) Update 3.


1 Answers

(From comments ...)

It was probably omitted because it is o/s level metadata. Assuming creation date is supported on your o/s, try using java.nio:

<cfscript>
   physicalPath = "c:/path/to/someFile.ext";

   // Get file attributes using NIO
   nioPath = createObject("java", "java.nio.file.Paths").get( physicalPath, [] );
   nioAttributes = createObject("java", "java.nio.file.attribute.BasicFileAttributes");
   nioFiles = createObject("java", "java.nio.file.Files");
   fileAttr = nioFiles.readAttributes(nioPath, nioAttributes.getClass(), []);

   // Display NIO results as date objects
   writeOutput("<br> creation (date): "& parseDateTime(fileAttr.creationTime()));
   writeOutput("<br> modified (date): "& parseDateTime(fileAttr.lastModifiedTime()));

   // Display CF results for comparison
   fileInfo = getFileInfo(physicalPath);
   writeDump(fileInfo);
</cfscript>
like image 51
Leigh Avatar answered Nov 04 '22 02:11

Leigh