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")
' Create a new file. The default is to overwrite any
' existing file with the same name.
Set ts = fso.CreateTextFile("C:\MyFile")
Example of Opening a Text File
Dim fso As FileSystemObject
Dim ts As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
' Open an existing file.
Set ts = fso.OpenTextFile("C:\MyFile", ForReading)
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.
- GetDrive - Returns DRIVE object.
- GetDriveName - Returns a STRING object.
Folder Methods
- CopyFolder(source, desination[,overwrite]) - Copy a FOLDER.
- CreateFolder(folderName) - Creates a FOLDER.
- DeleteFolder(path + folderName) - Deletes a FOLDER.
- FolderExists(path + folderName) - TRUE if FOLDER exists.
- GetFolder(path + folderName) - Returns a FOLDER object.
- GetParentFolderName(path)- Returns the Parent Path of a FOLDER.>
- MoveFolder(source, desination[,overwrite]) - Copy a FOLDER.
File Methods
- CopyFile(source, desination[,overwrite]) - Copy a FILE.
- CreateTextFile(filename) *- Create a TEXT FILE.
- OpenTextFile(filename, [mode], [create], [format])** - Open TEXT FILE.
- DeleteFile(path + fileName) - Deletes a FILE.
- FileExists(path + fileName) - TRUE if FILE exists.
- GetFile(path + fileName) - Returns a FILE object.
- MoveFile(source, desination[,overwrite]) - Move FILE.
* The default is to overwrite the file if it already exists. Use overwrite = False to prevent this.
**Mode = For reading, for writing, for appending.
Create = True/False, create the file if it doesn't exist. False is the default.
Format = Open as ASCII (default), Unicode or system default.
Text File Methods
- CreateTextFile(filename) *- Create a TEXT FILE.
- OpenTextFile(filename, [mode], [create], [format])** - Open TEXT FILE.
- Read
The OpenAsTextStream method opens a file and returns a TextStream object.
Copyright © 2006-2019, LQSystems,Inc. All rights reserved.