16,718
社区成员
发帖
与我相关
我的任务
分享
'获取指定目录下的所有文件名(包括子目录)(使用了递归调用)
Private Function DynamicList(ByVal strParentDir As String) As String()
Dim strSubDir() As String
Dim strSubFile() As String
Dim strSubSubFile() As String
If Tools.IsFileExist(strParentDir) Then
ReDim strSubFile(0)
strSubFile(0) = strParentDir
Else
Dim objDir As Directory
Dim I As Integer = 0
Try
strSubDir = objDir.GetDirectories(strParentDir)
strSubFile = objDir.GetFiles(strParentDir)
If Not IsNothing(strSubDir) Then
For I = 0 To strSubDir.Length - 1
strSubSubFile = DynamicList(strSubDir(I))
If Not IsNothing(strSubSubFile) Then Tools.UniteStrArrayA(strSubFile, strSubSubFile)
Next
End If
Catch e As Exception
AddSysLog("取要备份的文件列表时发生错误:" & e.Message & "(" & strParentDir & ")", EventLogEntryType.Error, 101)
strSubFile = Nothing
Finally
strSubDir = Nothing
strSubSubFile = Nothing
objDir = Nothing
End Try
End If
Return strSubFile
End Function
Public Sub UniteStrArrayA(ByRef Array1() As String, ByVal Array2() As String)
Dim intLength1 As Integer = 0
Dim intLength2 As Integer = 0
Dim I As Integer = 0
If Not IsNothing(Array1) Then intLength1 = Array1.Length
If Not IsNothing(Array2) Then intLength2 = Array2.Length
If intLength2 > 0 Then
If intLength1 = 0 Then
Array1 = Array2
Else
ReDim Preserve Array1(intLength1 + intLength2 - 1)
For I = intLength1 To Array1.Length - 1
Array1(I) = Array2(I - intLength1)
Next
End If
End If
intLength1 = Nothing
intLength2 = Nothing
I = Nothing
End Sub