VBScript » Objects » File

Version: 3.0

The File object allows you access and manipulate the various properties of a file.

Examples

Code:
<%
Dim filesys,demofile, createdate
Set filesys = CreateObject("Scripting.FileSystemObject")
Setdemofile = filesys.GetFile("filename")
createdate = demofile.DateCreated
%>
Output:
This code uses the GetFile method of the FileSystemObject object to create a File object and view one of its properties.

Properties

Attributes

Syntax: object.Attributes [ =newattributes]

This property allows us to get or change the various attributes of a file.

DateCreated

Syntax: object.DateCreated

This property gets the date and time that the file was created.

DateLastAccessed

Syntax: object.DateLastAccessed

Gets the date and time that the file was last accessed

DateLastModified

Syntax: object.DateLastModified

This property returns the date and time that the file was last modified.

Drive

Syntax: object.Drive

Returns the drive letter of the drive where the file is located.

Name

Syntax: object.Name

Lets us get or change the name of the specified file.

ParentFolder

Syntax: object.ParentFolder

This property gets the Folder object for the parent relating to the specified file.

Path

Syntax: object.Path

This property returns a file's path.

ShortName

Syntax: object.ShortName

Returns the short version of a filename (using the 8.3 convention). e.g. Employees.html is truncated to Employ~1.htm

ShortPath

Syntax: object.ShortPath

Returns the short version of the file path (this is the path with any folder and file names truncated as above).

Size

Syntax: object.Size

Returns the size of a file in bytes.

Type

Syntax: object.Type

Returns a string containing the file type description. e.g. For files ending in .TXT, "Text Document" is returned.

Methods

Copy

Syntax: object.Copy destination[, overwrite]

This method copies the selected file to the specified destination.

Delete

Syntax: object.Delete [force]

The method used to delete the file relating to the specified File object.

Move

Syntax: object.Move destination

This method is used to move the file relating to the specified File object to a new destination.

OpenAsTextStream

Syntax: object.OpenAsTextStream([iomode [,format]])

This method opens a specified file and returns an instance of a TextStream object that can then be manipulated - read from, written or appended to.

Events

Initialize

See Also: