CFCHART Experiment
One of the projects I’m working on has a number of disk space requirements and I decided to play around with CFCHART to give me an “at-a-glance” idea how much space is left on the drive without having to go into the server backend. I mostly used tips from Ray Camden’s site here.
Not much to it – like I said, it’s just an experiment so I didn’t jazz it up at all, but it works.
<cfset fileOb = createObject("java", "java.io.File").init("/")>
<cfset usable = #fileOb.getUsableSpace()#/1024/1024/1024>
<cfset total = #fileOb.getTotalSpace()#/1024/1024/1024>
<cfset used = total-usable>
<cfchart format="flash" chartHeight = "300" chartWidth = "600" foregroundcolor="Blue">
<cfchartseries type="pie" colorlist="blue,red">
<cfchartdata item = "Available" value = "#round(usable)#">
<cfchartdata item = "Used" value = "#round(used)#">
</cfchartseries>
</cfchart>
I’m working off my laptop with a 220 GB partition, 60 of which is taken. It says 161 free because it’s rounding, but the numbers are essentially right. The repeated use of 1024 simply bumps the value up from bytes to kilobytes to megabytes to gigabytes. Everything else is pretty self-explanitory. Good thing Ray Camden is around because I never would have figured out that frst line for myself.
Edit: In case anyone wonders, the first line in which I put “/” can be replaced with a specific drive such as “C:/” or “D:/” but I chose to use the webroot. Any linux path will also work.
