SunQuest
 
       Windows Scripting
  Home arrow Windows Scripting arrow Advanced Files and Folders in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Advanced Files and Folders in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-02-12

    Table of Contents:
  • Advanced Files and Folders in WSH
  • A Real-World Scenario
  • Examining File Attributes
  • Changing File Attributes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Advanced Files and Folders in WSH


    (Page 1 of 4 )

    In part one of this series we began to explore how we could use VBScript’s FileSystemObject in WSH to work with files and folders. In this installment we will look at some of the more advanced methods and techniques that this object has to offer. Let’s get our hands dirty and learn about some more advanced scripting techniques.

    We’ll start off with something useful.  One of the most common scripting uses of copying files and folders is for archival or backup purposes.  When moving large amounts of information it can be helpful to know how much drive space is available.

    To begin, we’ll create a simple script to demonstrate the information that is available to us.  Then we’ll create an actual, usable drive space script.  The following script demonstrates all of the Drive object’s properties.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set drive = objFso.GetDrive("C")

    With drive

       Wscript.Echo "Available Space:", .AvailableSpace

       Wscript.Echo "Drive Letter:", .DriveLetter

       Wscript.Echo "Drive Type:", .DriveType

       Wscript.Echo "File System:", .FileSystem

       Wscript.Echo "Free Space:", .FreeSpace

       Wscript.Echo "Is Ready:", .IsReady

       Wscript.Echo "Path:", .Path

       Wscript.Echo "Root Folder:", .RootFolder

       Wscript.Echo "Serial Number:", .SerialNumber

       Wscript.Echo "Share Name:", .ShareName

       Wscript.Echo "Total Size:", .TotalSize

       Wscript.Echo "Volume Label:", .VolumeName

    End With

    As you can see, we’re just making a listing of the values that each property returns.  A Cscript example should look something like this:

    Available Space: 82646454272

    Drive Letter: C

    Drive Type: 2

    File System: NTFS

    Free Space: 82646454272

    Is Ready: -1

    Path: C:

    Root Folder: C:

    Serial Number: 1208326009

    Share Name:

    Total Size: 119949254656

    Volume Label:

    The values here are pretty self-explanatory.  Keep in mind that all sizes are listed in bytes.  Let’s take a look at the two values that you may be scratching your head over at the moment—DriveType and IsReady.

    In Visual Basic, when a numeric value is converted to a Boolean, 0 becomes False and all other values become True.  When a Boolean is converted to a numeric data type, False becomes 0 and True becomes -1.

    The IsReady property simply returns a Boolean value indicating whether or not the drive is ready to be used.  True means the drive is ready while False indicates that it’s not.  Therefore, IsReady returns False if the drive is currently in use.

    DriveType Constants

    0 = Unknown

    1 = Removable

    2 = Fixed

    3 = Network

    4 = CD-ROM

    5 = RAM Disk

    The DriveType property returns one of the DriveType constants listed in the table to the left based upon the type of drive being analyzed.

    You should also keep in mind that the Share Name property will only return a value if the DriveType Property returns 3 for a remote drive.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · It this article we finish up our series by taking a look at the advanced methods...
     

    WINDOWS SCRIPTING ARTICLES

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway