|
-
Sep 20th, 2000, 05:04 AM
#1
Thread Starter
Addicted Member
Hi guys
I'm trying to change the following code to suit my needs and was wondering could someone help.
Instead of getting the size of just one file I want to set up an array and get the size of a range of files. Then I want to compare this with another array. Does ayone know how to do this.
Thanks
JK
Code:
'code by Sam Hugill from VBSquare
Function FileSize(File As String) As String
Dim LSize As String
If File = "" Then
FileSize = ""
Exit Function
End If
LSize = FileLen(File)
FileSize = LSize 'Size in bytes
End Function
Private Sub Command1_Click()
MsgBox FileSize("c:\windows\explorer.exe")
End Sub
-
Sep 20th, 2000, 05:16 AM
#2
Here is an example:
Code:
Private Type File_Info
sFileName As String
lFileSize As Long
End Type
Private Sub Form_Load()
Dim sFolder1 As String
Dim sFolder2 As String
Dim sFile As String
Dim lCounter1 As Long
Dim lCounter2 As Long
Dim fiArray1() As File_Info
Dim fiArray2() As File_Info
ReDim fiArray1(0)
ReDim fiArray2(0)
sFolder1 = "C:\Folder1\"
sFolder2 = "C:\Folder2\"
'Read Contentents of Folder
sFile = Dir(sFolder1 & "*.*")
Do Until sFile = ""
'Add File Info to the array
fiArray1(UBound(fiArray1)).sFileName = sFile
fiArray1(UBound(fiArray1)).lFileSize = FileLen(sFolder1 & sFile)
'Expand the array for the next item
ReDim Preserve fiArray1(UBound(fiArray1) + 1)
sFile = Dir
Loop
'Remove the last item cause its empty
If UBound(fiArray1) > 0 Then
ReDim Preserve fiArray1(UBound(fiArray1) - 1)
End If
'Read Contentents of Folder
sFile = Dir(sFolder2 & "*.*")
Do Until sFile = ""
'Add File Info to the array
fiArray2(UBound(fiArray2)).sFileName = sFile
fiArray2(UBound(fiArray2)).lFileSize = FileLen(sFolder2 & sFile)
'Expand the array for the next item
ReDim Preserve fiArray2(UBound(fiArray2) + 1)
sFile = Dir
Loop
'Remove the last item cause its empty
If UBound(fiArray2) > 0 Then
ReDim Preserve fiArray1(UBound(fiArray2) - 1)
End If
If UBound(fiArray1) > 0 And UBound(fiArray2) > 0 Then
'Start Compare
For lCounter1 = LBound(fiArray1) To UBound(fiArray1)
For lCounter2 = LBound(fiArray2) To UBound(fiArray2)
If fiArray1(lCounter1).lFileSize = fiArray2(lCounter2).lFileSize Then
Debug.Print fiArray1(lCounter1).sFileName & " has the same size as " & fiArray2(lCounter2).sFileName
End If
Next
Next
End If
End Sub
-
Sep 20th, 2000, 05:20 AM
#3
Thread Starter
Addicted Member
hi Azzmodan
thanks a lot buddy.
-
Sep 20th, 2000, 05:31 AM
#4
Thread Starter
Addicted Member
Hi
I just tried to use the code and got an error message: User Defined type not defined. And it points to
Code:
Dim fiArray1() As File_Info
Any ideas what this means??
Thanks again
-
Sep 20th, 2000, 06:19 AM
#5
It means you forgot to incluse the:
Private Type File_Info
sFileName As String
lFileSize As Long
End Type
In the declaration section fo your form
Code:
'>Declaration section
Option Explicit
Private Type File_Info
sFileName As String
lFileSize As Long
End Type
'>Start of code
Sub Form_Load()
'blablabla
End Sub
-
Sep 20th, 2000, 06:41 AM
#6
Thread Starter
Addicted Member
Thanks a lot for that I wasn't paying attention. In the last section I tried to add a MsgBox just to see that the code ran through.
Code:
If UBound(fiArray1) > 0 And UBound(fiArray2) > 0 Then
'Start Compare
For lCounter1 = LBound(fiArray1) To UBound(fiArray1)
For lCounter2 = LBound(fiArray2) To UBound(fiArray2)
If fiArray1(lCounter1).lFileSize = fiArray2(lCounter2).lFileSize Then
MsgBox "This passed ok"
Debug.Print fiArray1(lCounter1).sFileName & " has the same size as " & fiArray2(lCounter2).sFileName
End If
Next
Next
End If
End Sub
But the message box won't appear for me. Sorry in advance if it's a stupid question. Thanks
JK
-
Sep 20th, 2000, 07:36 AM
#7
If the messagebox doesn't appear it most like is because none of the files in the 1st folder have the same size as those in the 2nd folder.
It only prints stuff when 2 files have exactly the same size.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|