Private Sub CopyDir(ByVal srcPath As String, ByVal aimPath As String) Try ' 检查目标目录是否以目录分割字符\结束,如果不是则添加之 If aimPath.Substring(aimPath.Length - 1) <> Path.DirectorySeparatorChar Then aimPath += Path.DirectorySeparatorChar End If '判断源目录是否存在,不存在则退出. If (Not Directory.Exists(srcPath)) Then Exit Sub '' 判断目标目录是否存在如果不存在则新建之 'If (Not Directory.Exists(aimPath)) Then Directory.CreateDirectory(aimPath) ' 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组 Dim fileList() As String = Directory.GetFileSystemEntries(srcPath) ' 遍历所有的文件和目录 For Each FileName As String In fileList ' 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 If Directory.Exists(FileName) Then If (Not Directory.Exists(aimPath + Path.GetFileName(FileName))) Then Directory.CreateDirectory(aimPath + Path.GetFileName(FileName)) CopyDir(FileName, aimPath + Path.GetFileName(FileName)) ' 否则直接Copy文件 Else File.Copy(FileName, aimPath + Path.GetFileName(FileName), True) End If Next Catch ex As Exception Response.Write("<br>" + ex.ToString()) End Try End Sub
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。