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

Overwrite existing file/control with VB code 1

Status
Not open for further replies.

482570

Technical User
Apr 15, 2007
6
US
Hello and I need your help again please!!
I used following code to moving file from one location to other and working just fine so far.
Problem now is if some how either source or destination has same file, then code is stop running and message show file already existing.
I'm thinking just overwrite file or given user choice.
Is there anyone can help me on this?
Your help is greatly appreciated.


Dim oFSO
Dim sSourceFile
Dim sDestinationFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

sSourceFile = "C:\Data\*.*"
sDestinationFile = "C:\Data2\"

oFSO.MoveFile sSourceFile, sDestinationFile

' Clean Up

Set oFSO = Nothing




End Sub
 
faq222-2244 gives guidance on forum usage, including basic research. Your VBHelp file will show that the FSO has methods called GetFileName and DeleteFile. Use these to see if the file exists, and delete the existing file if required.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top