VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
"Folder" Objects Representing File Folders
This section describes Folder object and its properties and methods. A tutorial example is provided on how to list all properties of a file folder.
Folder: An object representing a folder in a file system. It offers the following properties and methods:
The following VBScript example showing you how the Folder object can be used to list all the information about a folder:
<html> <body> <!-- folder_test.html - Copyright (c) 2002 HerongYang.com. All Rights Reserved. --> <pre> <script language="vbscript"> ' Creating a FileSystemObject object set fs = CreateObject("Scripting.FileSystemObject") ' Getting a specific folder set f = fs.GetFolder("c:\inetpub\wwwroot") call displayFolderInfo(f) ' Displaying folder information sub displayFolderInfo(f) document.writeln("Path = " & f.Path) document.writeln("Name = " & f.Name) document.writeln("Short Name = " & f.ShortName) document.writeln("Short Path = " & f.ShortPath) document.writeln("Drive = " & f.Drive) document.writeln("Size = " & f.Size) document.writeln("Attributes = " & f.Attributes) document.writeln("Date created = " & f.DateCreated) document.writeln("Is Root Folder = " & f.IsRootFolder) set l = f.SubFolders for each sf in l document.writeln("Sub Folder = " & sf.Name) next set l = f.Files for each sf in l document.writeln("File = " & sf.Name) next end sub </script> </pre> </body> </html>
When you load this example into IE, you will get a security warning. You can ignore it and get the output:
Tests on the folder tree: Path = C:\Inetpub\wwwroot Name = wwwroot Short Name = wwwroot Short Path = C:\inetpub\wwwroot Drive = c: Size = 439424 Attributes = 48 Date created = 4/19/2000 3:16:15 PM Is Root Folder = False Sub Folder = asp Sub Folder = aspnet_client Sub Folder = images Sub Folder = list Sub Folder = _private Sub Folder = _vti_cnf Sub Folder = _vti_log Sub Folder = _vti_pvt Sub Folder = _vti_script Sub Folder = _vti_txt File = default.asp File = default.htm File = hello.asp File = hello.html File = help.gif File = iisstart.asp File = localstart.asp File = mmc.gif File = pageerror.gif File = postinfo.html File = print.gif File = warning.gif File = web.gif File = win2000.gif File = _vti_inf.html
Table of Contents
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
Variable Declaration and Assignment Statement
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
►scrrun.dll - Scripting Runtime DLL Library
Scripting Runtime DLL Library Overview
"Dictionary" Objects to Store Keys and Values
"FileSystemObject" Objects to Manage File Systems
"Drive" Objects Representing Disk Drives
►"Folder" Objects Representing File Folders
"File" Objects Representing Files
"TextStream" Objects Representing File Input and Output
IE Web Browser Supporting VBScript