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

Overwrite the file

Status
Not open for further replies.

oops4me

Programmer
Jul 7, 2003
50
IN
Hello,
I am copying the file from source path to destination path using
FileSource="C:\abc.doc"
FileDest="C:\c1.doc"
FileSystem.FileCopy FileSource, FileDest
first time it works fine as there is no file c1.doc
but if i use it for overwriting file then it is giving me error as permission denied.

can anybody give me the solution for it or tell me how to overwrite file using vb without giving message box of overwriting the file.
 
look to see if it exists already then delete it

Code:
if FileSystem.FileExists(FileDest)then
  FileSystem.FileDelete(FileDest)
end if
FileSystem.FileCopy FileSource, FileDest

You can also put a message box warning in there
Code:
dim msg as VbMsgBoxResult
if FileSystem.FileExists(FileDest)then
  msg = msgbox("This file exists press ok to overwrite",vbOKCancel,"Error")
  if msg = vbOK then
    FileSystem.FileDelete(FileDest)
    FileSystem.FileCopy FileSource, FileDest
  end if
end if

}...the bane of my life!
 
Why don't you use fso?
Code:
   Dim fso As FileSystemObject
   fso.CopyFile "C:\abc.doc", "C:\c1.doc", True
The last argument to the copy file procedure is the overwrite, which is set to true by default.
-Max
 
hello
thanx for your help.
please tell me how to use filesystemobject in VB.
it is giving me error at line where i ve written
Dim fso As FileSystemObject
as "user defined type not defined "
we have to select any reference library?
 
>we have to select any reference library?
Microsoft Scripting Runtime

and you said
>first time it works fine as there is no file c1.doc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top