<CFTRY>
<CFOBJECT TYPE="COM" CLASS="Scripting.FileSystemObject" NAME="FSO" ACTION="CONNECT">
<CFCATCH type="ANY">
<CFOBJECT TYPE="COM" CLASS="Scripting.FileSystemObject" NAME="FSO" ACTION="CREATE">
</CFCATCH>
</CFTRY>
Getting the drives:
-------------------------
Next we will make a collection of all the drives:
<CFSET Drives = FSO.Drives>
This can be any type of drives. Fixed drives, network drives etc.
Now we can just output the number of drives found:
<CFOUTPUT>
Number of Drives : #Drives.Count#<BR>
</CFOUTPUT>
Outputting the drive information:
----------------------------------
The first thing we do is to create a table for this information:
<TABLE cellspacing="1" cellpadding="5">
<TR>
<TD>Drive</TD>
<TD>Total Size</TD>
<TD>Free Space</TD>
<TD>Available Space</TD>
<TD>Serial No.</TD>
<TD>Path</TD>
<TD>Type</TD>
<TD>Ready?</TD>
<TD>Name</TD>
<TD>System</TD>
</TR>
Next thing is to loop over the collection:
<CFLOOP COLLECTION="#Drives#" ITEM="this">
<CFIF this.DriveLetter is not "A">
The cfif above can be removed if you don't have any disabled floppy-drives
<cfoutput>
<TR>
Display the Drive Letter
<TD>#this.DriveLetter#</TD>
Display the Total size
<TD><CFIF this.isReady AND ISDefined("this.TotalSize")>
#NumberFormat(round(evaluate(this.TotalSize/1000000)))# Mb
</CFIF>
</TD>
Display the free space
<TD>
<CFIF this.isReady AND ISNumeric(this.FreeSpace)>
#NumberFormat(round(evaluate(this.FreeSpace/1000000)))# Mb
</CFIF>
</TD>
Display the available space
<TD>
<CFIF this.isReady AND IsNumeric(this.AvailableSpace)>
#NumberFormat(round(evaluate(this.AvailableSpace/1000000)))# Mb
</CFIF>
</TD>
Display the serial number
<TD>
<CFIF this.isReady AND LEN(this.SerialNumber)>
#this.SerialNumber#
</CFIF>
</TD>
Display the path
<TD>#this.path#</TD>
The type will come back as the following values:
Const DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5
So we'll use CFSWITCH statements to display the actual type
<TD>
<CFSWITCH expression="#this.DriveType#">
<CFCASE value="1">Removable</CFCASE>
<CFCASE value="2">Fixed</CFCASE>
<CFCASE value="3">Network</CFCASE>
<CFCASE value="4">CD ROM</CFCASE>
<CFCASE value="5">Ram Disk</CFCASE>
<CFDEFAULTCASE>Unknown</CFDEFAULTCASE>
</CFSWITCH>
</TD>
Display if the Drive is ready
<TD>#this.isReady#</TD>
Here we have to display the drive name. Before that, we will
check if it is a network drive or not. If it is a network drive,
then we display the 'sharename'; otherwise, we display the 'volumename'.
<TD>
<CFIF this.isReady>
<CFIF this.DriveType IS "3">
#this.ShareName#
<CFELSE>
#this.VolumeName#
</CFIF>
</CFIF>
</TD>
Display the type of Filesystem
<TD><CFIF this.isReady>#this.FileSystem#</CFIF></TD>
</TR>
</cfoutput>
</CFIF>
</CFLOOP>
</TABLE>
If you have any questions/remarks/errors left please
use the forums or the feedback form.
discuss this topic to forum
