Jump to content

Recommended Posts

Posted

Hello,

I need to find out how to replace one file with another in Visual Basic 6. Say I need to replace the file C:\Program Files\Folder\test.txt with the file C:\Program Files\documents\test.txt . How would I write that? Thank You for your help


Posted

Using the default VB6 library you can do it like that...

Kill "C:\Program Files\Folder\test.txt"
FileCopy "C:\Program Files\documents\test.txt", "C:\Program Files\Folder\test.txt"

It's not the perfect code but it work (with an error handler).

To prevent an error with Kill you can remove the read-only attribute with SetAttr before calling Kill.

And it's not a good idea to have hard coded path like that (use variable instead).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...