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 1

Status
Not open for further replies.

jennuhw

MIS
Apr 18, 2001
426
US
I am having problems with filesystemobject. I have one that checks to see if a folder exists and works, but another won't copy a file. I get a syntax error. Here is my code:

Code:
Dim fso, fs As Scripting.FileSystemObject
Set fso = New FileSystemObject
Set fs = New FileSystemObject

If Not fso.FolderExists(filepath) Then  'this works
    fso.CreateFolder (filepath)
End If

'these lines cause the syntax error
'fs.CopyFile (tempname, filepath) 
fs.CopyFile ("c:\autoexec.bat", "c:\temp")

Anyone have any ideas? Thanks!
 
Try this:

fs.CopyFile "c:\autoexec.bat", "c:\temp"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
And this ?
fs.CopyFile "c:\autoexec.bat", "c:\temp\", True
Anyway you don't need 2 fso objects, one suffice.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I did the fs.CopyFile ("c:\autoexec.bat", "c:\temp") as a test to see if it would work with files that I knew existed. The real line that I need to work is 'fs.CopyFile (tempname, filepath). I think that Tom's thing worked! Stinking parenthesis! Thanks!!


[ponytails]
 
Old post, but.. Use Call when using parathesis and passing multiple arguments

Randall Vollen
National City Bank Corp.
 
I am trying to find an answer to "User-defined type not defined error" when using the dim FileSystemObject

I know it is an add-in of sorts, but have not been able to find it
 
Either use late binding, or set a reference to Microsoft Scripting Runtime (in VBE - Tools | References)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top