Results 1 to 3 of 3

Thread: Problem when checking for valid filetype

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    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:
    1. Public Function GetFileType(xFile As String) As String
    2.     On Error Resume Next
    3.     Dim ID As String * 300
    4.  
    5.     Open xFile For Binary Access Read As #1
    6.     Get #1, 1, ID
    7.     Close #1
    8.     GetFileType = Mid(ID, 9, 8)
    9. End Function
    10.  
    11.  
    12.  
    13. Private Sub cmdCheck_Click()
    14.   Dim ct As Integer
    15.   Dim a As String
    16.   Dim Valid_type As String
    17.  
    18.   ct = 0
    19.   a = sPath & Dir(sPath & "*.avi")
    20.   Valid_type = GetFileType(a)
    21.  
    22.   Do While LenB(a) > LenB(sPath)
    23.    
    24.     If Valid_type = "AVI LIST" Then
    25.     ct = ct + 1
    26.     End If
    27.    
    28.     a = sPath & Dir
    29.   Loop
    30.  
    31. Msgbox ct
    32.  
    33. End Sub

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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:
    1. Private Sub cmdCheck_Click()
    2.   Dim ct As Integer
    3.   Dim a As String
    4.   Dim Valid_type As String
    5.  
    6.   ct = 0
    7.   a = sPath & Dir(sPath & "*.avi")
    8.  
    9.  
    10.   Do While LenB(a) > LenB(sPath)
    11.     [b]Valid_type = GetFileType(a) [/b]  
    12.     If Valid_type = "AVI LIST" Then
    13.     ct = ct + 1
    14.     End If
    15.    
    16.     a = sPath & Dir
    17.   Loop
    18.  
    19. Msgbox ct
    20.  
    21. End Sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Problem when checking for valid filetype

    Yes, that works fine. Thank you for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width