-
Feb 4th, 2012, 09:37 PM
#1
Thread Starter
Lively Member
Resolved - copying & over riding file
Hi Guys,
I have code that copies from path folder and then copies it over to the destination folder when button is clicked.
problem is it won't overide if there is bin file in that directory allready.
how can I over come this problem?
HTML Code:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "c:\toolbox\nandpro\nand1.bin"
Dim destination As String = "c:\toolbox\360multi\data\my360\nanddump.bin"
If IO.File.Exists(path) And Not File.Exists(destination) Then
IO.File.Copy(path, destination)
Label1.Text = "File Copied Successfully"
Else
Label1.Text = "There is already a file called test.txt in the Destination Folder"
End If
End Sub
End Class
Last edited by VbAzza; Feb 6th, 2012 at 08:45 AM.
Reason: resloved
-
Feb 5th, 2012, 12:57 AM
#2
Re: copying & over riding file
All you had to do was what really should have been obvious: read the documentation. The MSDN documentation for the File.Copy method answers your question. That's about 30 seconds to a minute to open the documentation, find the topic and read. ALWAYS read the documentation first.
-
Feb 5th, 2012, 01:47 AM
#3
Thread Starter
Lively Member
Re: copying & over riding file
thanks for the input.
I' still confused sorry not every day vb programmer just self taught
sorry if I'm asking for sample
Regards
VbAzza
-
Feb 5th, 2012, 02:10 AM
#4
Re: copying & over riding file
When you followed my instructions from my previous post and read the documentation, what exactly did you not understand? You have read the documentation, right?
-
Feb 5th, 2012, 02:14 AM
#5
Addicted Member
Re: copying & over riding file
The VB.Net IDE could even tell you what jmcilhinney was talking about...
IO.File.Copy(path, destination)
is the same as
IO.File.Copy(path, destination, false)
The 3rd parameter is the overwrite flag. True = Overwrite, False = No Overwrite
-
Feb 5th, 2012, 03:52 AM
#6
Thread Starter
Lively Member
Re: copying & over riding file
do you have link for this
it seems we are not on the same page
thanks
VbAzza
-
Feb 5th, 2012, 04:11 AM
#7
Re: copying & over riding file
Here's a link: http://www.google.com.au/search?q=vb...ient=firefox-a
If you can't search the web then maybe programming is a bit of a stretch.
-
Feb 6th, 2012, 04:20 AM
#8
Thread Starter
Lively Member
Re: copying & over riding file
jmcilhinney,
I do apologies for not being up to scratch - but there is no need to down talk people who have different learning capabilities.
now i know how you got those 70 odd thousand posts
I belong to various forums its seems this forum has egotistical issues. It must be some trend that people think it's cool.
maybe we should go back to the old days and bang on 2 rocks and some twigs & forget posting help questions in forums.
VbAzza
-
Feb 6th, 2012, 08:11 AM
#9
Hyperactive Member
Re: copying & over riding file
You have received help which is straight forward to follow.
No one has spoken down to you, instead you have ignored any help provided and as such provoked the quote below.
Originally Posted by jmcilhinney
If you can't search the web then maybe programming is a bit of a stretch.
-
Feb 6th, 2012, 08:22 AM
#10
Re: copying & over riding file
vbnet Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim path As String = "c:\toolbox\nandpro\nand1.bin" Dim destination As String = "c:\toolbox\360multi\data\my360\nanddump.bin" IO.File.Copy(path, destination, True) End Sub
This will overwrite the file. The reason the guys above were a little rough with you is because the answer you needed was an overly trivial matter that a couple seconds reading the Intellisense could have helped you resolve. People here are not elitist and are always willing to help....but sometimes you really can help yourself.
-
Feb 6th, 2012, 08:42 AM
#11
Thread Starter
Lively Member
Re: copying & over riding file
thanks for the help and apologies I have mild autism which make learning little more difficult than the average person
I worked out a code which i think maybe right
HTML Code:
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim FileToCopy As String
Dim NewCopy As String
FileToCopy = "c:\toolbox\nandpro\nand1.bin"
NewCopy = "c:\toolbox\360multi\data\my360\nanddump.bin"
If IO.File.Exists(NewCopy) = True Then
End If
Dim overwrite As Integer
overwrite = MessageBox.Show("Do you want to overwrite the existing file", "Overwrite file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If overwrite = vbYes Then
System.IO.File.Delete(NewCopy)
System.IO.File.Copy(FileToCopy, NewCopy)
MessageBox.Show("Successfully Copied" & vbNewLine & FileToCopy & "to" & NewCopy)
ElseIf overwrite = vbNo Then
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|