FileSystemObject? Is This VB6.0's Object for File Manipulation?


I'm a beginning VB6.0 learner and I'm trying to write a small VB program which copies/backsup VB files I'm working on into a directory/folder on a FAT16 drive (WIN98 is FAT32 and NT is NTFS). This will enable me to work with these files when I run NT ( NTFS ).

I understand (I think enough) objects in that everything in the VB world (as in the C++ world) is an object, which has properties and methods. All of the help documentation describes the methods associated with file manipulation(i.e. file I/O, writing to, reading from, appending, COPYING) as being part of an object known as: FileSystemObject.

Yet, when I try to create (instantiate) an instance of this object,
as in:

Option Explicit
'Dim fso As FileSystemObject

Private Sub cmdStart_Click()
    MsgBox "Copying files. . . ."
    FileCopy "d:\Program Files\Microsoft Visual     Studio\VB98\Works_In_Progress\*.*",     "c:\VB_Shared_Backup\"
    MsgBox "All done!"

End Sub

It didn't like the fso object declaration, which is why it's
commented out. Using FileCopy as above seems to do something until I click "OK" and then I get error #52, "Bad file name or number".

This seems to me to be somewhat straightforward, but it's not.
If I try to define an object of type FileSystemObject as in:

Option Explicit
Dim fileObject As FileSystemObject

I receive a "User-defined type not defined." error.

Which method associated with which object(s) is/are needed here?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

did you, in project references  add "microsoft scrpting runtime" (scrrun.dll) ?

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "source", "dest"
If you read the VB helpfile you ought to see what is the problem with your FileCopy statement.

"FileCopy Statement

Copies a file."

This means that the two parameters MUST be single files, using tokens won't work. You will have to scan thru the directories and copy the files that are inside.

Listing the files in a directory is really simple, you can check out for a couple of solutions.

In most cases using the FileSystemObject means unnecessary large overhead and you depend on M$ not screwing things up with version-compatibility stuff etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jnowlinAuthor Commented:
Thanks jbil. I had *not* added Microsoft
Scripting Runtime to the project, as this is still fairly new to me. When I added it, SCRRUN.DLL, the error message regarding the user-defined type being undefined went away.

Thanks to hes, also. Between your code and jbil's comment, I now have a basic, working program. This is all I needed to do at this early stage. I agree with
VBmaster that there are more efficient and effective ways to code this. Now, I can work up to the challenge, I can now
"tweak" this program and modify it to suit different file copying needs and get it to run with minimal overhead.
I'll now go to the Web site that you've suggested VBmaster.

jnowlinAuthor Commented:
Thanks VBmaster.

is a tremendous resource for VB. It's really going to be helpful.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.