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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject Help with Creating Folder

Status
Not open for further replies.

hblackorby

Programmer
Feb 13, 2001
164
US
Hi,
My pure VB is a litte rusty from all the ASP do I, but hopefully someone can help me. I'm trying to copy a program link from a CD-ROM to the windows desktop and the start menu.

Private Sub Form_Load()
'On Error GoTo goterror
Dim FSO As FileSystemObject
FileCopy App.Path & "\TDD4.lnk", "c:\windows\desktop\TDD4.lnk"
MsgBox "Copying Menu " & App.Path & "\TDD4.lnk", vbOKOnly, "Copying File..."
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists("c:\windows\startm~1\programs\tdd4") Then
FS0.CreateFolder ("c:\windows\startm~1\programs\tdd4")
End If
FileCopy App.Path & "\TDD4.lnk", "c:\windows\start menu\programs\tdd4\TDD4.lnk"
Unload Me
'goterror:
' MsgBox "There was an error setting the link to the desktop.", vbOKOnly, "Error Setting Up Link"
' Unload Me
End Sub

Yes, I have Microsoft Scripting checked as a reference. It is giving me "Object Rquired" when I try to create the folder. Note that the .FolderExists method works fine.

Any help at all would be appreciated. I never have problems with the FSO in ASP, just in VB it seems.

Thanks, Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
Never Mind. I had a typo in my code that said FS0 and not FSO (zero vs. "o"). Oh well. Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
I was on the verge of spotting the error when I saw that you found it already. Good eyes!

Two remarks:

1. Unless you have a compelling reason to use Late Binding i.e. CreateObject ... , you better use Early Binding i.e.
Set FSO = New Scripting.FileSystemObject
for performance reasons.

You are probably using VBScript (which only allows for variant data types) and not the VB language compiler (which does allow for strong data typing), in which case you have no choice but to use Late Binding

2. You mix and match FSO methods and traditional VB statements (CopyFile). FSO supplies the same functionality with better control of the situation through the FSO.CopyFile (strSourceName, strDestName, bOverWrite) method.

- strSourceName can contain wild card characters
- Method fails if strDestName already exists and bOverWrite=False. Note that the default for bOverWrite is True!

You can also check if the strSourceName file exists before copying with the FSO.FileExists (strSourceName) method prior to the Copying operation. _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top