[thelist] Determining file size in CF5

Aaron Johnson lists at cephas.net
Mon Jan 6 17:34:01 CST 2003


Hi Seth,

> I'm trying to write some Cold Fusion that needs to know the size of a
> file that's stored locally (i.e., not an uploaded file, so CFFILE does
> me no good).  How do I determine the size of said file without using a
> CFDIRECTORY call and looping through the (potentially huge) list of
> files returned?
If you're using CFMX, you can do it quite easily by dropping into
Java... in fact here's a function for it:

function FileSize(filePath) {
  Var result = 0;
  Var fileObject = CreateObject("JAVA", "java.io.File");
  fileObject.init(filePath);
  if (fileObject.isFile()) {
     result = fileObject.length();
  }
  Return result;
}

Also, check out cflib.org filesys lib which has a couple functions (not
including the one mentioned above, although I've submitted it) for
getting the size of a file:

http://www.cflib.org/library.cfm?ID=8

AJ

--
Aaron Johnson
http://cephas.net/blog/
ajohnson at cephas.net




More information about the thelist mailing list