Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - 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 - Changing File Attributes


    (Page 4 of 4 )

    We’ve seen how to check for the existence of a file attribute.  Now let’s learn how to set them.  We can simply assign the Attributes property with whatever attribute value we choose in order to change it.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFso.GetFile("C:boot.ini")

     

    objFile.Attributes = 35

    This code sample essentially removes the System attribute from the boot.ini file.  We’ve manually set it to 35 which is: Read-only, Hidden, and Archive.

    But what if we don’t want to set it manually?  What if we just want to check for the existence of an attribute and set it if it isn’t there?  The next code snippet will check our file to see if the System attribute is set.  If it isn’t, it will add it without changing any of the other existing attributes.

    Const SYSTEM = 4

     

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFso.GetFile("C:boot.ini")

     

    If NOT objFile.Attributes AND SYSTEM Then

       objFile.Attributes = objFile.Attributes + SYSTEM

    End If

    We’ve taken a piece of our code that checks if a value is set and modified the conditional statement slightly.  Instead of checking to see if it is set, we’re checking to see if it is NOT set.  If it isn’t, then we add the value to the existing attribute value.

    That wraps up this segment.  Stick around for my next article.  In the final part of this series we’ll learn how to use the FileSystemObject to write good error-checking to avoid unwanted errors when working with files and folders.  We’ll also take a brief look at how to deal with files and folders on a remote machine.  See you then.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 2 hosted by Hostway
    Stay green...Green IT