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

CopyFile gives a Error (FSO)

Status
Not open for further replies.

HydraNL

Technical User
May 9, 2005
74
NL
Hi,

This is the first time I heard of the FileSystemObject. Of course I have to know how to use it. And of course... it doesn't work for me.

I want to copy a file from the hard disk to a folder. this is the code I used (just testing):)
Code:
Private Sub Command1_Click()
Dim FSO As New FileSystemObject
Dim f As File

  Set f = FSO.CopyFile("C:\test.txt, "C:\TEST", True)
End Sub
I'm getting a compile error. Someone knows what I'm doing wrong? If someone knows where to find some simpel examples, please place them.
 
Did you set reference to Microsoft Scripting Runtime?
Are you sure that CopyFile method is a function that returns file object?
 
Copyfile return nothing (empty). Set is of wrong use. You can get rid of dim f.
[tt] FSO.CopyFile "C:\test.txt, "C:\TEST", True[/tt]
 
vladk is right about the CopyFile function NOT returning a file object. You're also missing a quote.

Your code should look like this...

Code:
Private Sub Command1_Click()
    Dim FSO As New FileSystemObject

    Call FSO.CopyFile("C:\test.txt[b]"[/b], "C:\TEST", True)
    Set FSO = Nothing
End Sub

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi, thank you all for the replies.

I'm getting Run-time error '70' Permision denied. I did set the reference to "Microsoft Scripting Runtime
 
There are 3 things I suggest you check.

1) Make sure you have permissions to read the file.
2) Make sure you have permissions to write in to the target folder.
3) Make sure the source file is not already open (either by another application or your own application).

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thank for the reply george. I have full acces and permissions. That is the weird thing.
 
I don't know what's the deal. But
[tt]>Dim FSO As New FileSystemObject
Dim FSO As New [red]Scripting.[/red]FileSystemObject[/tt]

All the op's successive posts, is it supposed the set f line is corrected? Never heard a word on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top