' isOrNot 判断是否要拷贝
'fromFile 要拷贝的文件
'toPath 指定文件存放的位置
Private Function CopyFile(ByVal isOrNot As Boolean, ByVal fromFile As String, ByVal toPath As String)
If isOrNot = True Then
Dim strFolderName As String = fromFile.Substring(fromFile.LastIndexOf("/") + 1, fromFile.Length - fromFile.LastIndexOf("/") - 1)
If Not Directory.Exists(toPath & "/" & strFolderName) Then
Directory.CreateDirectory(toPath & "/" & strFolderName)
End If
Dim strFiles As String() = Directory.GetFiles(fromFile)
For i As Integer = 0 To strFiles.Length - 1
Dim fileName As String = strFiles(i).Substring(strFiles(i).LastIndexOf("/") + 1, strFiles(i).Length - strFiles(i).LastIndexOf("/") - 1)
File.Copy(strFiles(i), toPath & "/" & strFolderName & "/" & fileName, True)
Next
Dim dirInfo As DirectoryInfo = New DirectoryInfo(fromFile)
Dim ziPath As DirectoryInfo() = dirInfo.GetDirectories()
For j As Integer = 0 To ziPath.Length - 1
Dim strZiPath As String = fromFile & "/" & ziPath(j).ToString()
CopyFile(True, strZiPath, toPath & "/" & strFolderName)
Next
End If
End Function
第一次写技术性文章,有不对的地方希望大家来指正!谢谢!