?
Solved

Getting file sizes

Posted on 2012-08-30
3
Medium Priority
?
562 Views
Last Modified: 2012-08-30
I need to loop through a bunch of directories and look at specific files and get their current filesize.
Using <cfdirectory> wont work because I don't need to get the filesize of entire directories, just specific files that I am determining in my loop.  The files and their paths are being pulled from a database query.
I looked into <cffile> but the read attribute pulls the entire file into memory.

What is a good way to do this?

Thanks
0
Comment
Question by:WebStalkers
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 38351323
All depends on how many files and where they're located.

If it's a few files OR they're scattered across many different directories,  you could look them up individually.  Run your db query. Loop hrough it and use GetFileInfo() on each file:

            <cfloop query="yourDBQuery">
                        <cfset info = GetFileInfo( fullPathToTheFile )>
                        <cfset sizeInBytes = info.size>
                         ... do something
            </cfloop>

If the files are mostly in the same directory, it could save time to use cfdirectory. Do one listing, then loop through it to find the sizes of the files you need.  Don't forget you can use "filters" (ie on file name, extension, ...)

           <cfdirectory filter="*.jpg" ....>  
           <cfdirectory filter="*.xls|*.png" ....>

Either of these would work. The most efficient approach really depends on your files.
0
 
LVL 2

Author Comment

by:WebStalkers
ID: 38351364
I just happened to find this function.  I've never used it before..very nice!

Thanks!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38351366
Using <cfdirectory> wont work because I don't need to get the filesize
        of entire directories, just specific files that I am determining in my loop.  


One thing I forgot to clarify.  cfdirectory doesn't calculate the sizes of directories afaik - only files.  For directories it just returns 0.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question