-
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
-
Nov 16th, 2012, 08:06 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|