Copying file or Filess, copying directory directories, to different path or drive on-VBForums
Results 1 to 2 of 2

Thread: Copying file or Filess, copying directory directories, to different path or drive on

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    8

    Copying file or Filess, copying directory directories, to different path or drive on

    First I would like to thank the person who helped me by providing this code. Many thanks to kevininstructor

    Here is the sample code


    Public Class Form1
    Private Sub Button1_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Dim DirectoryName As String = "C:\MyDatabase"
    Dim SourceFile As String = IO.Path.Combine( _
    System.Environment.GetFolderPath( _
    Environment.SpecialFolder.MyDocuments), "MyOffice\MData.accdb")

    If Not IO.Directory.Exists(DirectoryName) Then
    Try
    IO.Directory.CreateDirectory(DirectoryName)
    Catch ex As Exception
    MessageBox.Show( _
    String.Format("Failed to create folder '{0}'{1}{2}", _
    DirectoryName, _
    Environment.NewLine, _
    ex.Message))
    Exit Sub
    End Try
    End If

    Label1.Text = "Now Moving Database to the folder '" & DirectoryName & "'"

    Try
    IO.File.Copy(SourceFile, IO.Path.Combine(DirectoryName, "MData.accdb"))
    MessageBox.Show("Done copy operation.")
    Catch ex As Exception
    MessageBox.Show( _
    String.Format("Failed to copy file '{0}'{1}{2}", _
    SourceFile, _
    Environment.NewLine, _
    ex.Message))
    End Try
    End Sub
    End ClassKevin If you could please help by comment next to each code line so I can understand how is it working like functioning. Since I really want to learn it.

    Also can this code be modified to copy a whole directory located in sub folder of special folder? if so can you please provide sample tell how to do so.

    Best regards and thanks again for the help

  2. #2
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,533

    Re: Copying file or Filess, copying directory directories, to different path or drive

    To copy a directory see FileSystem.CopyDirectory Method which has several overloads. In regards to commenting lines of code, a better method for you to learn is take something like IO.Directory.CreateDirectory and Google it. Using IO.Directory.CreateDirectory as an example in Google the first link gives you the MSDN documentation. Also take say IO.Directory and Google it, again the first link provides details for IO.Directory, some functions will have examples while others will not. If they don't have examples do some more web searches and if you don't find what you are looking for post a question here. Along the way mark web sites that have good information such as Dot Net Perls or home and learn.

    Before I forget, Special Folders, using Google you should it http://msdn.microsoft.com/en-us/libr...ialfolder.aspx

    No matter where you find code always work with Option Strict On. If something does not work with Option Strict On post a question here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.