Question: How to find out when file was created in ColdFusion

Question

How to find out when file was created in ColdFusion

Answers 1
Added at 2016-12-16 10:12
Tags
Question

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?

Answers
nr: #1 dodano: 2016-12-16 20:12

(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>
Source Show
◀ Wstecz