XMetaL Tips and Tricks

XMetaL Community Forum XMetaL Tips and Tricks Script Example: Using the File System Object (FSO) to Obtain Drive Information

  • Derek Read

    Script Example: Using the File System Object (FSO) to Obtain Drive Information

    Participants 1
    Replies 0
    Last Activity 11 years, 11 months ago

    Product(s):
    XMetaL Author, XMetaL Developer

    Description:
    You may find you need to gather information about a specific drive when writing a script for use with XMetaL Author. For example, you may wish to decide if there is enough space left to write out a particular file, or whether a particular user has access to a specific network share.

    Legal:
    * Licensed Materials – Property of JustSystems, Canada, Inc.
    *
    * (c) Copyright JustSystems Canada, Inc. 2010
    * All rights reserved.
    *
    *——————————————————————-
    * The sample contained herein is provided to you “AS IS”.
    *
    * It is furnished by JustSystems Corporation as a simple example and has not been
    * thoroughly tested under all conditions. JustSystems Canada, Inc., therefore, cannot
    * guarantee its reliability, serviceability or functionality.
    *
    * This sample may include the names of individuals, companies, brands and products
    * in order to illustrate concepts as completely as possible. All of these names are
    * fictitious and any similarity to the names and addresses used by actual persons or
    * business enterprises is entirely coincidental.
    *———————————————————————

    [u]Example:[/u]
    The following JScript example demonstrates how to instantiate the Windows File System Object (FSO) to read information for the drive containing the current user's TEMP folder. It builds on information located in the following forum post that shows how to check the value of Windows System Variables to find out which folder is the user's TEMP folder: http://forums.XMetaL.com/index.php/topic,27.0.html

    This is not meant to be a complete reference and may have omitted some variables. Please refer to Microsoft's documentation if you need to obtain the value for a setting not listed here.

    [code]//XMetaL Script Language JScript:
    function getDriveInfo(drvPath)
    {
       var fso, drv, s =””;
       fso = new ActiveXObject(“Scripting.FileSystemObject”);
       drv = fso.GetDrive(fso.GetDriveName(drvPath));
       s += “Specified Path: ” + drvPath + “n”;
       s += “DriveLetter: ” + drv.DriveLetter + “n”;
       switch (drv.DriveType)
       {
          case 0: t = “Unknown”; break;
          case 1: t = “Removable”; break;
          case 2: t = “Fixed”; break;
          case 3: t = “Network”; break;
          case 4: t = “CD-ROM”; break;
          case 5: t = “RAM Disk”; break;
       }
       s += “DriveType: ” + t  + “n”;
       s += “SerialNumber: ” + drv.SerialNumber  + “n”;
       s += “FileSystem: ” + drv.FileSystem  + “n”;
       s += “IsReady: ” + drv.IsReady  + “n”;
       if (drv.ShareName == “”)
    s += “ShareName: [not a share]n”;
       else
    s += “ShareName: ” + drv.ShareName  + “n”;
       s += “VolumeName: ” + drv.VolumeName + “n”;
       s += “Path: ” + drv.Path + “n”;
       s += “RootFolder: ” + drv.RootFolder + “n”;
       s += “Total Size: ” + drv.TotalSize / 1024 +” bytes” + “n”;
       s += “Free Space: ” + drv.FreeSpace / 1024 + ” bytes” + “n”;
       s += “Available Space: ” + drv.AvailableSpace + ” bytes” + “n”;
      fso = null;
       return s;
    }

    //Example: show drive information for drive containing user's TEMP folder
    var wsh     = new ActiveXObject(“Wscript.Shell”);
    var envVars = wsh.Environment(“PROCESS”);
    var userTempDir = envVars.Item(“TEMP”);
    Application.MessageBox(getDriveInfo(userTempDir),64);
    wsh = null;
    [/code]

    External References:

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support