getFileInfo

Returns information about on-disk or in-memory file. Return struct contains keys such as: lastModified, size, path, name, type, canWrite, canRead, isHidden and more.

getFileInfo(path) → returns struct

Argument Reference

path string
Required

Path to the on-disk or in-memory file

Examples
Sample code invoking the getFileInfo function

myFile = getTempFile(getTempDirectory(),"testFile");
fileInfo = getFileInfo(myFile);
isReadable = (not fileInfo.canRead ? 'un' : '')&'readable';
isWritable = (not fileInfo.canWrite ? 'un' : '')&'writable';
isHidden = (not fileInfo.isHidden ? 'not ' : '')&'hidden';
date = DateTimeFormat(fileInfo.lastModified,'full');
fileSize = NumberFormat(fileInfo.size / 1000 / 1000,'0.00');
writeOutput('"'&fileInfo.name&'" is '&isReadable&', '&isWritable&' and '&isHidden&'. ');
writeOutput('It was at last modified at '&date&' and has a size of '&fileSize&' MB');

Expected Result: "testFile9217639658547923751.tmp" is readable, writable and not hidden. It was at last modified at Friday, November 3, 2017 3:58:08 PM UTC and has a size of 0.00 MB

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub