How do I use the FSO?
August 14, 2000
To be able to use the FSO to perform all your dirty work, you must
first create the object. If you're familiar with creating objects
in ASP pages, then this next line should be no surprise:
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
%>
We create the FSO here and set the reference to the variable fso.
We can now use the familiar object.method syntax to perform file system
manipulations. (Check out the
Visual Basic documentation
to learn more about objects and object
oriented programming.) In this case, we can use fso.method or fso.
property, as we'll see in upcoming examples.
|
NOTE:
The FSO model is located in the scripting runtime dll
provided by Microsoft, scrrun.dll. You can reference this dll
in any application that can reference objects, such as
MS Access, Word, and a whole slew of others. This means
you're not restricted to just using the FSO in an ASP page.
|
Here is an abridged list of methods available to the
FSO that we will use here to manipulate files:
|
File Methods |
|
CopyFile |
Copies one or more files from one
place to another |
|
CreateTextFile |
Creates a file and returns a TextStream
object |
|
DeleteFile |
Deletes a file |
|
OpenTextFile |
Opens a file and returns a TextStream
object that can be used to read from or append to the file |
For a complete list of all the methods and properties of the FSO,
check out
the Microsoft MSDN reference. Let's move onto some examples.
The wonders of the File System Object
The wonders of the File System Object
Writing Files
|