[英]Copying subfolders with their own files to another folder with WebClient in VB.NET
I'm copying an array of subfolders and array of files of the subfolders, the process is successful, but the files that are copied has no size. 我正在复制子文件夹数组和子文件夹文件数组,该过程成功完成,但是复制的文件没有大小。 the
60 MB
file became 0 bytes
after being copied to another directory, what could be wrong? 将
60 MB
文件复制到另一个目录后变为0 bytes
,这可能是什么问题?
this Is my code: 这是我的代码:
Dim WithEvents WebCopy As New WebClient
Dim foldersToCopy As New ArrayList()
Dim filesOfSub As New ArrayList()
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
foldersToCopy.Clear()
filesOfSub.Clear()
Dim src As String = Form2.TextBox1.Text
Dim dest As String = Form2.TextBox2.Text
Dim di As DirectoryInfo = New DirectoryInfo(src)
Dim dii As DirectoryInfo = New DirectoryInfo(dest)
' this is where I get the subfolders and its files.
For Each sd In di.GetDirectories
For Each fi In sd.GetFiles
If Not Directory.Exists(dest & "\" & sd.Name) And Not File.Exists(dest & "\" & fi.Name) Then
foldersToCopy.Add(sd.Name)
filesOfSub.Add(fi.Name)
End If
Next
Next
' this is where I create the subfolders
For i = 0 To foldersToCopy.Count - 1
If Not Directory.Exists(dest & "\" & dii.Name) Then
Directory.CreateDirectory(dest & "\" & foldersToCopy(i))
End If
Next
' this is where I copy the files of subfolders
For i = 0 To filesOfSub.Count - 1
Dim WebCopy As WebClient = New WebClient
WebCopy.DownloadFileAsync(New Uri(src & "\" & filesOfSub(i)), dest & "\" & foldersToCopy(i) & "\" & filesOfSub(i))
Next
End Sub
Btw, I'm using WebClient
for its smooth progress bar and convinient use of handlers. 顺便说一句,我正在使用
WebClient
的顺利进度条和方便使用的处理程序。
Thank GOD I have found out the answer! 谢谢上帝,我已经找到答案了!
WebCopy.DownloadFileAsync(New Uri(src & "\" & foldersToCopy(i) & "\" & filesOfSub(i)), dest & "\" & foldersToCopy(i) & "\" & filesOfSub(i))
this should be the correct form of my DownloadFileAsync
copier. 这应该是我的
DownloadFileAsync
复印机的正确形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.