에는이 코드에 몇 가지 문제가 있습니다. 실제로는 디렉토리/폴더의 모든 파일을 반복하여 dir1array (ctr1) 및 dir2array (ctr2)에 값을 할당하려고합니다. 이 배열을 작동시키는 방법이 있습니까?배열을 사용하여 vba의 폴더에있는 파일에 액세스하는 방법은 무엇입니까?
Option Explicit
'*********************************************************************
'* Verify if files have the same name before proceeding to compare *
'* their length *
'* DYNAMIC ARRAYs *
'*********************************************************************
Sub findMatchFilenames()
'Dim fso As fileSystemObject
Dim objMapinfo
Dim fso As New Scripting.FileSystemObject
Dim dir1 As Folder
Dim dir2 As Folder
Dim file1 As File
Dim file2 As File
Dim dir1array() As String
Dim dir2array() As String
ReDim dir1array(0 To 100) As String
ReDim dir2array(0 To 100) As String
Dim ctr1 As Integer
Dim ctr2 As Integer
Dim lLen1 As Long, lLen2 As Long
Dim myFile As String, text As String, textline As String
Set fso = New FileSystemObject
Set dir1 = fso.GetFolder("c:\Temp\")
Set dir2 = fso.GetFolder("c:\Tempo\")
ctr1 = 0
For Each file1 In dir1.Files
ctr2 = 0
For Each file2 In dir2.Files
dir1array(ctr1) = file1.Name
dir2array(ctr2) = file2.Name
If dir1array(ctr1) = dir2array(ctr2) Then
MsgBox "" & dir1array(ctr1) & "" & dir2array(ctr2)
Debug.Print file1.Name & " matches " & file2.Name
lLen1 = FileLen(file1)
lLen2 = FileLen(file2)
If lLen1 <> lLen2 Then
Exit Sub
Else
MsgBox "The files have the same length"
End If
End If
ctr2 = ctr2 + 1
Next file2
ctr1 = ctr1 + 1
Next file1
Close #1
End Sub
안녕하세요.이 코드에는 몇 가지 문제가 있습니다. 실제로는 디렉토리/폴더의 모든 파일을 반복하여 dir1array (ctr1) 및 dir2array (ctr2)에 값을 할당하려고합니다. 이 배열을 작동시키는 방법이 있습니까? 도와 줘서 고마워. – user3405572
모듈 상단에 'Option Explicit'을 추가하고 컴파일 ... '끝'경우 커플 '다음'... 어쩌면 더 ... 코드 수정 및 다시 게시 –
전체를 다시 게시했습니다. 지금 코드. 아시다시피 나는 코드 끝에 bytArr1 (lCtr) 및 byArr2 (lCtr) 배열과 비슷한 문제가 있습니다. – user3405572