Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pls help with FSO

Status
Not open for further replies.

ATHUEL

Technical User
Joined
Sep 23, 2002
Messages
29
Location
US
Pls,
I need to use the FileSystemObjet objet but i don´t understand some things:

1_Here is an example of the MSDN library

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close

I don´t understand the porpouse of the "fs" and the "a" in the code.
Are they variables? I have to declare them?
in that case are they objet variables?

I want to use this to create copy and delete some folders...
 
No need to declare anything unless you have OPTION EXPLICIT (and you should!). In that case, you can declare fs and a as OBJECTs. Be sure to set your References to include the Microsoft Scripting Library.

Note the use of the SET keyword. That says fs and a must be objects of some kind. CreateObject creates an object (DUH!) of the sort indicated by its argument. The CreateTextFile method of the FileSystemObject returns a TextStream object.

Here's what I consider to be a more straightforward example:

Code:
'Copy testfile.txt to testfile.cpy
Dim fs As FileSystemObject
Set fs = New FileSystemObject
fs.CopyFile "c:\testfile.txt", "c:\testfile.cpy", True
Set fs = Nothing
[\code]

By declaring fs, you get the Intellisense stuff in VB so you know what kinds of methods and properties you can fool with as you type.  Also note that since fs is an object, you should deallocate it when you're done (Set fs = Nothing).

Good luck!

Glenn
 
ok ! thanks 3gm
I think that I get it now !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top