Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - 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 
Mobile Linux 
App Generation ROI 
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


    Advanced Files and Folders in WSH - A Real-World Scenario


    (Page 2 of 4 )

    Let’s take a real-world example.  The following script will simply return some information about the free space on the drive.  You could easily use this code snippet in a script of your own to monitor drive space.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set drive = objFso.GetDrive("C")

    With drive

       Wscript.Echo "There is " & .AvailableSpace & " of " & .TotalSize _

          & " bytes available on drive " & .Path

       Wscript.Echo

       Wscript.Echo "That means that drive " & .RootFolder _

           & " contains " & .FreeSpace & " bytes of free space"

    End With

    You should see an output like this:

    There is 82645839872 of 119949254656 bytes available on drive C:

     

    That means that drive C: contains 82645839872 bytes of free space

    Of course, if you’re like me, those numbers are still pretty obscure, right?  Don’t worry, I’ve included a conversion function for you to use.  Feel free to change it any way you like.  Basically, it takes the number of bytes as a single string input and converts it to the nearest usable unit size.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set drive = objFso.GetDrive("C")

    With drive

       Wscript.Echo "There is " & ConvertBytes(.AvailableSpace) _

           & " of " & ConvertBytes(.TotalSize) & " available on drive " _

           & .Path

       Wscript.Echo

       Wscript.Echo "That means that drive " & .RootFolder _

           & " contains " & ConvertBytes(.FreeSpace) & " of free space"

    End With

    Here’s the output of our script after using the ConvertBytes function.

    There is 77 GB of 111.7 GB available on drive C:

     

    That means that drive C: contains 77 GB of free space

    That makes it much more readable in my opinion. 

    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

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT