Results 1 to 11 of 11

Thread: Resolved - copying & over riding file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    80

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    80

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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?

  5. #5
    Addicted Member
    Join Date
    Oct 2010
    Posts
    178

    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    80

    Re: copying & over riding file

    do you have link for this

    it seems we are not on the same page

    thanks

    VbAzza

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    80

    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

  9. #9
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    278

    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.

    Quote Originally Posted by jmcilhinney
    If you can't search the web then maybe programming is a bit of a stretch.

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: copying & over riding file

    vbnet Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim path As String = "c:\toolbox\nandpro\nand1.bin"
    4.         Dim destination As String = "c:\toolbox\360multi\data\my360\nanddump.bin"
    5.  
    6.         IO.File.Copy(path, destination, True)
    7.     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.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    80

    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
  •  



Click Here to Expand Forum to Full Width