File System Object
by Linda Quinn
Close Window
Create an instance of the file system object:
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Select scrrun.dll as a Reference.
FileSystemObject Object Model
FileSystemObject
Drives
Drive
Folders
Folder
Files
File
TextStream
Example of Creating a Text File
Dim fso As FileSystemObject
Dim ts As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\MyFile")
ts.writeline = "This is a new line."
Example of Opening a Text File
Dim fso As FileSystemObject
Dim ts As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\MyFile", ForReading)
Do While Not ts.AtEndOfStream
strtext = ts.readline
ts.MoveNext
Loop
Reading through a Folder
Dim fs As FileSystemObject
Dim f As Folder
Dim fc As Files
Dim fl As File
Set fs = CreateObject("Scripting.filesystemobject")
Set f = fs.GetFolder(xpath)
Set fc = f.Files
For Each fl In fc
If Left(fl.Name, Len(3)) = "JV1" Then
cmpy = Mid(fl.Name, 7, 3)
Next fl
FileSystemObject Methods
Drive Methods
- DriveExists Returns a BOOLEAN value.
- GetDriveReturns DRIVE object.
- GetDriveNameReturns a STRING object.
Folder Methods
- CreateFolderCreates a FOLDERobject.
- DeleteFolderDeletes a FOLDER object.
- GetFolderReturns a FOLDER object.
- GetParentFolderNameReturns a STRING object.
=================================================================
This content was created by Linda Quinn of LQNet.
See http://www.lqnet.com for a great
collection of articles on this and other topics.
=================================================================
Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.
====================================================================
Want an expert to help with your project?
LQ Systems, Inc.
Business Solutions
====================================================================