File System Object

This is an additional library that offers clear, object-orientated access to all the common file and directory functions.
This object is not part of the Office library and requires you to add an additional reference to your project.
SS - References dialog
Once the reference has been added you can use the Object Browser to find out more about the objects.
The Microsoft Scripting Runtime is a library that can be added to a Project using (Tools > References).
This library is located in C:\Windows\System32\scrrun.dll

Dim objFSOFileSystemObject As Scripting.FileSystemObject 
Set objFSOFileSystemObject = CreateObject("Scripting.FileSystemObject")

Types of Objects

FileSystemObject - This is also a top level object used for accessing drives, folders and files.
Drive - This belongs to the Drives collection and refers to particular local or network drive.
Folder - This object refers to a particular folder.
File - This object refers to a particular file.
TextStream - This object refers to a stream of text that can be read from, written to or appended to a text file.
Dictionary - This is the top level object


FileSystemObject Object

The FileSystemObject object is the object that actually gives you access to a system's files using 27 methods and only one property.
When creating folders you must create them, one level at a time. You cannot create a folder and a subfolder at the same time.
You should always use the server names instead of the letters as different PC's may have different letters assigned
We won't try to define all of the methods, but we'll review a few as we use them in code examples a little later.
In addition, FileSystemObject is used to return an object that can create, read and edit text files (ASCII and Unicode).
Once you have a new instance of the FileSystemObject, you can work with drives, folders and files, which provide easy access to the file system and simplify the process of reading and writing to a text file.

Dim objFSOFileSystemObject As New Scripting.FileSystemObject 

Alternatively

Dim objFSOFileSystemObject As Scripting.Dictionary 
Set objFSOFileSystemObject = New Scripting.FileSystemObject

Alternatively

Dim objFSOFileSystemObject As Object 
Set objFSOFileSystemObject = CreateObject("Scripting.FileSystemObject")

Important

Unfortunately the FileSystemObject is not suitable for working with binary data. For this you must use the traditional functions.


© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited TopPrevNext