Problem when checking for valid filetype
Hello, I'm using the code below to check how many valid avi videos there are in a folder.
Every time a valid avi video has been found, 1 should be counted up (ct). This works fine if there are only valid avi videos in the folder, but if I rename a mp3 audio file to .avi and put that file in the folder with the valid avi videos, then ct always returns "0".
Does anybody know what is wrong?
VB Code:
Public Function GetFileType(xFile As String) As String
On Error Resume Next
Dim ID As String * 300
Open xFile For Binary Access Read As #1
Get #1, 1, ID
Close #1
GetFileType = Mid(ID, 9, 8)
End Function
Private Sub cmdCheck_Click()
Dim ct As Integer
Dim a As String
Dim Valid_type As String
ct = 0
a = sPath & Dir(sPath & "*.avi")
Valid_type = GetFileType(a)
Do While LenB(a) > LenB(sPath)
If Valid_type = "AVI LIST" Then
ct = ct + 1
End If
a = sPath & Dir
Loop
Msgbox ct
End Sub
Re: Problem when checking for valid filetype
You are checking the File type only once, so it will return only one. Try this instead:
VB Code:
Private Sub cmdCheck_Click()
Dim ct As Integer
Dim a As String
Dim Valid_type As String
ct = 0
a = sPath & Dir(sPath & "*.avi")
Do While LenB(a) > LenB(sPath)
[b]Valid_type = GetFileType(a) [/b]
If Valid_type = "AVI LIST" Then
ct = ct + 1
End If
a = sPath & Dir
Loop
Msgbox ct
End Sub
Re: Problem when checking for valid filetype
Yes, that works fine. Thank you for your help :)