01.
Imports
System
02.
Imports
System.IO
03.
04.
Public
Class
Form1
05.
06.
Private
Sub
Form1_Load(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
MyBase
.Load
07.
DirectoryCopy(
"D:\Test"
,
"C:\"
,
True
)
08.
End
Sub
09.
10.
11.
Private
Shared
Sub
DirectoryCopy( _
12.
ByVal
sourceDirName
As
String
, _
13.
ByVal
destDirName
As
String
, _
14.
ByVal
copySubDirs
As
Boolean
)
15.
16.
17.
Dim
dir
As
DirectoryInfo =
New
DirectoryInfo(sourceDirName)
18.
Dim
dirs
As
DirectoryInfo() = dir.GetDirectories()
19.
20.
If
Not
dir.Exists
Then
21.
Throw
New
DirectoryNotFoundException( _
22.
"Source directory does not exist or could not be found: "
_
23.
+ sourceDirName)
24.
End
If
25.
26.
27.
If
Not
Directory.Exists(destDirName)
Then
28.
Directory.CreateDirectory(destDirName)
29.
End
If
30.
31.
Dim
files
As
FileInfo() = dir.GetFiles()
32.
For
Each
file
In
files
33.
Dim
temppath
As
String
= Path.Combine(destDirName, file.Name)
34.
file.CopyTo(temppath,
False
)
35.
Next
file
36.
37.
38.
If
copySubDirs
Then
39.
For
Each
subdir
In
dirs
40.
Dim
temppath
As
String
= Path.Combine(destDirName, subdir.Name)
41.
DirectoryCopy(subdir.FullName, temppath, copySubDirs)
42.
Next
subdir
43.
End
If
44.
End
Sub
45.
End
Class