
vb开发-扫描一个包含子文件夹的文件夹,将该文件夹下包括子文件夹内包含特殊关键字的文件复制到指定路径
1个回答
展开全部
Private Sub GetAllFile(ByVal path As String)
Try
Dim strDir As String() = System.IO.Directory.GetDirectories(path)
Dim strFile As String() = System.IO.Directory.GetFiles(path)
Dim i As Integer
If strFile.Length > 0 Then
For i = 0 To strFile.Length - 1
int = int + 1
Dim info As New FileInfo(strFile(i))
size = size + info.Length
ListBox1.Items.Add(strFile(i) & " : " & Format((info.Length / 1024), "0.00").ToString & "KB")
Dim file As New StreamWriter("list.log", True)
file.WriteLine(strFile(i) & " : " & Format((info.Length / 1024), "0.00").ToString & "KB")
File.Close()
Next
End If
If strDir.Length > 0 Then
For i = 0 To strDir.Length - 1
GetAllFile(strDir(i))
Next
End If
Catch ex As Exception
End Try
End Sub
Try
Dim strDir As String() = System.IO.Directory.GetDirectories(path)
Dim strFile As String() = System.IO.Directory.GetFiles(path)
Dim i As Integer
If strFile.Length > 0 Then
For i = 0 To strFile.Length - 1
int = int + 1
Dim info As New FileInfo(strFile(i))
size = size + info.Length
ListBox1.Items.Add(strFile(i) & " : " & Format((info.Length / 1024), "0.00").ToString & "KB")
Dim file As New StreamWriter("list.log", True)
file.WriteLine(strFile(i) & " : " & Format((info.Length / 1024), "0.00").ToString & "KB")
File.Close()
Next
End If
If strDir.Length > 0 Then
For i = 0 To strDir.Length - 1
GetAllFile(strDir(i))
Next
End If
Catch ex As Exception
End Try
End Sub
追问
谢谢你,这个问题我已经解决了...我还想请教一下,我想一次扫描多个文件夹。比如在两个不同盘符下的文件夹1和文件夹2...这个是不是要用到数组?怎么写啊
追答
写一个查询类,开两个线程同时查询就可以了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询