6

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?

Maxim
  • 98
  • 7
  • 4
    It was probably omitted because it is o/s level metadata. Assuming it is supported on your o/s, [try using java.nio](http://stackoverflow.com/questions/2723838/determine-file-creation-date-in-java#2724009). – Leigh Dec 16 '16 at 13:10

1 Answers1

6

(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>
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Thanks for the solution, but I get following error on line 5: Object Instantiation Exception. Class not found: java.nio.file.Paths – Maxim Dec 19 '16 at 07:24
  • It should exist in most later versions of java. What version of CF and JVM are you running? – Leigh Dec 19 '16 at 15:24
  • Coldfusion 10. Never mind, Lastmodified will do for me – Maxim Dec 21 '16 at 10:53
  • Worked fine for me, except for the parseDateTime part. That requires CF11+. – Leigh Dec 21 '16 at 14:29
  • if you just need the parameters themselves, they can be picked up in ColdFusion using GetFileInfo(absolutepath).parameter. Dates are given in ordinary CF timestamp format, and can be manipulated with the ordinary CF datetime functions. – Betty Mock Jan 24 '21 at 23:54