PowerBasic Museum 2020-A

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Windows Script Runtime => Source Code => Scripting => FileSystemObject => Topic started by: José Roca on July 14, 2008, 02:44:47 AM

Title: IFileSystem.GetDrive Method
Post by: José Roca on July 14, 2008, 02:44:47 AM


The following example illustrates the use of the GetDrive method.

JScript


function GetFreeSpace(drvPath)
{
   var fso, d, s ="";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   d = fso.GetDrive(fso.GetDriveName(drvPath));
   s = "Drive " + drvPath.toUpperCase( ) + " - ";
   s += d.VolumeName + "<br>";
   s += "Free Space: " + d.FreeSpace/1024 + " Kbytes";
   return(s);
}



VBScript


Function GetFreeSpace(drvPath)
   Dim fso, d, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set d = fso.GetDrive(fso.GetDriveName(drvPath))
   s = "Drive " & UCase(drvPath) & " - "
   s = s & d.VolumeName   & "<BR>"
   s = s & "Free Space: " & FormatNumber(d.FreeSpace/1024, 0)
   s = s & " Kbytes"
   GetFreeSpace = s
End Function


PowerBASIC


FUNCTION GetFreeSpace (BYVAL strDrvPath AS STRING) AS STRING

   LOCAL fso AS IFileSystem
   LOCAL d AS IDrive
   LOCAL s AS STRING
   LOCAL v AS VARIANT

   fso = NEWCOM ("Scripting.FileSystemObject")
   d = fso.GetDrive(fso.GetDriveName(UCODE$(strDrvPath)))
   s = "Drive " & UCASE$(strDrvPath) & " - "
   s = s & ACODE$(d.VolumeName) & $CRLF
   v = d.FreeSpace
   s = s & "Free Space: " & FORMAT$(VARIANT#(v) / 1024)
   s = s & " Kbytes"
   FUNCTION = s

END FUNCTION