"File" Objects Representing Files

This section describes File object and its properties and methods. A tutorial example is provided on how to list all properties of a file.

File: An object representing a file in a file system. It offers the following properties and methods:

Here is a VBScript example showing you how to get detailed information about a file.

<!-- file_test.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
<script language="vbscript">
   ' Creating a FileSystemObject object
   set fs = CreateObject("Scripting.FileSystemObject")

   ' Display detailed information about this file
   set f = fs.GetFile("c:\winnt\system32\scrrun.dll")
   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)

When you load this example into IE, you will get a security warning. You can ignore it and get the output:

Tests on the File class:
Path = C:\WINNT\system32\scrrun.dll
Name = scrrun.dll
Short Name = scrrun.dll
Short Path = C:\winnt\system32\scrrun.dll
Drive = c:
Size = 147512
Attributes = 32
Date created = 6/26/2001 6:06:58 PM

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 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

 Built-in Functions

 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

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)


 PDF Printing Version