|
-
Nov 16th, 2012, 03:41 PM
#1
Thread Starter
New Member
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
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
|