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:
"Attributes": Property to return the attributes of the file.
"DateCreated": Property to return the date and time when the file was created.
"DateLastAccessed": Property to return the date and time when the file was last accessed.
"DateLastModified": Property to return the date and time when the file was last modified.
"Drive": Property to return the driver letter of the file.
"Name": Property to return the name of the file.
"ParentFolder": Property to return the "Folder" object of the parent folder.
"Path": Property to return the path string of the file.
"ShortName": Property to return the name of the file in 8.3 format.
"ShortPath": Property to return the path string of the file in 8.3 format.
"Size": Property to return the size of the file in bytes.
"Copy(destination[,true|false])": Method to copy the file to the specified destination. The optional
argument [true|false] specifies that the copy operation will override the existing file.
"Delete([true|false])": Method to delete the file. The optional [true|false] argument specifies
that the delete operation will delete the read-only file.
"Move(destination)": Method to move the file to the specified destination.
"OpenAsTextStream([io_mode[,tristate]])": Methode to open the file and return
a TextStream object representing the I/O stream to that file.
io_mode(=1|2|8: ForReading|ForWriting|ForAppending) specifies how the file should be openned.
tristate(=-2|-1|0: TristateUserDefault|TristateTrue|TristateFalse) speficies if the file should
be open as Unicode or not.
Here is a VBScript example showing you how to get detailed information about a file.
<html>
<body>
<!-- file_test.html
- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<pre>
<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)
</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 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