Files Collection Object (VB6)

Description

The Files collection object is a container for File objects that is returned by the Files property of any Folder object. All files contained in the folder are included in the Files collection object. You can obtain a reference to an individual File object using the Files collection object's Item property; this takes the exact filename, including the file extension, as a parameter. To iterate through the collection, you can use the For Each...Next statement.

The Files collection object is one of the objects in the File System object model; for an overview of the model, including the library reference needed to access it, see the File System object model entry.

Createable

No

Returned by

Folder.Files property

Properties

Count

Data Type: Long

The number of File objects in the collection.

Item

Data Type: File Object

Takes the filename (including the file extension) as a parameter and returns the File object representing the file with that name. Individual File objects can't be accessed by their ordinal position in the collection. Item is the Files collection object's default property. The following code fragment uses the Item property to retrieve the autoexec.bat File object:

Dim ofsFileSys As New FileSystemObject Dim ofsFiles As Files Dim ofsFile As File Set ofsFiles = ofsFileSys.Drives("C").RootFolder.Files Set ofsFile = ofsFiles.Item("autoexec.bat") MsgBox ofsFile.DateCreated & vbCrLf & _ ofsFile.DateLastModified & vbCrLf & _ ofsFile.DateLastAccessed ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.