Results 1 to 10 of 10

Thread: [RESOLVED] little issue here...

  1. #1

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Resolved [RESOLVED] little issue here...

    here's the code...
    VB Code:
    1. TempC = 0
    2.     Set FindIt = New Class1
    3.     ret = FindIt.Search(File1.Path, "*.jpg")
    4.    
    5.       If ret(0) = 0 Then
    6.         MsgBox "No Picture files found in specified folder or sub folders."
    7.         Exit Sub
    8.       End If

    now, i would like it to find jpg's, bmp's, etc, i tried using...

    VB Code:
    1. TempC = 0
    2.     Set FindIt = New Class1
    3.     ret = FindIt.Search(File1.Path, "*.jpg;*.jpeg;*.gif;*.bmp")
    4.    
    5.       If ret(0) = 0 Then
    6.         MsgBox "No Picture files found in specified folder or sub folders."
    7.         Exit Sub
    8.       End If

    but then then msgbox returns with "No Picture files found in specified folder or sub folders" If i try to just change the "*.jpg" to "*.bmp" that works but wont find the jpg's. Any solution?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: little issue here...

    Quote Originally Posted by thekurbster
    Any solution?
    Not without seeing the code in your class that does the search.

  3. #3

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    Quote Originally Posted by Hack
    Not without seeing the code in your class that does the search.

    here's the class
    VB Code:
    1. Option Explicit
    2.  
    3. 'Use this class to find a file in a given directory
    4. 'using a custom mask.
    5. '
    6. 'The function Search(Path as string, Mask as string) returns
    7. 'a variant array containing all the files (with path) that
    8. 'match the mask filter provided.
    9. 'The index 0 of the array returned contains how many files
    10. 'were found
    11. '
    12. 'The event ChangeDir is raised whenever the function changes
    13. 'to another directory
    14. '
    15. 'NOTE: This class uses Windows API functions to find the files,
    16. 'not the Visual Basic Dir function, because of the way it
    17. 'must be called.
    18. 'Also, the Visual Basic GetAttr function is not used because
    19. 'it does not handle correcty some files. Instead, I prefer
    20. 'using the GetFileAttribute API.
    21. '
    22. Event ChangeDir(Path As String)
    23. Private Type FILETIME
    24.   dwLowDateTime As Long
    25.   dwHighDateTime As Long
    26. End Type
    27. Private Type WIN32_FIND_DATA
    28.   dwFileAttributes As Long
    29.   ftCreationTime As FILETIME
    30.   ftLastAccessTime As FILETIME
    31.   ftLastWriteTime As FILETIME
    32.   nFileSizeHigh As Long
    33.   nFileSizeLow As Long
    34.   dwReserved0 As Long
    35.   dwReserved1 As Long
    36.   cFileName As String * 260
    37.   cAlternate As String * 14
    38. End Type
    39. Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    40. Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    41. Private Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
    42. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
    43. Private Files() As String
    44.  
    45. Private Sub FindFiles(Path As String, Mask As String)
    46.   Dim FindInfo As WIN32_FIND_DATA
    47.   Dim TmpFile As String
    48.   Dim Handler As Long, Result As Long
    49.  
    50.   If Right(Path, 1) <> "\" Then Path = Path + "\"
    51.   Handler = FindFirstFile(Path + Mask, FindInfo) 'Get the first file
    52.   If Handler = -1 Then Exit Sub 'If there is no file, just exit sub
    53.   RaiseEvent ChangeDir(Path)
    54.   DoEvents 'Without this, the event is useless
    55.   Do
    56.     TmpFile = Left(FindInfo.cFileName, InStr(FindInfo.cFileName, vbNullChar) - 1) 'Truncate all the null chars at the end of the string
    57.     If (GetFileAttributes(Path + TmpFile) And vbDirectory) <> vbDirectory Then 'If the filename is not a directory...
    58.       ReDim Preserve Files(UBound(Files) + 1) '...allocate a new item in the array
    59.       Files(UBound(Files)) = Path + TmpFile
    60.     End If
    61.     Result = FindNextFile(Handler, FindInfo) 'Get the next file
    62.   Loop Until Result = 0 'Loop until there are no more files
    63.   FindClose Handler 'We don't want to waste useful memory in this crap, right?
    64. End Sub
    65.  
    66. Private Sub FindDirectories(Path As String, Mask As String)
    67.   Dim FindInfo As WIN32_FIND_DATA
    68.   Dim TmpFile As String
    69.   Dim Handler As Long, Result As Long
    70.  
    71.   If Right(Path, 1) <> "\" Then Path = Path + "\"
    72.   FindFiles Path, Mask
    73.   Handler = FindFirstFile(Path + "*.*", FindInfo) 'Get the first subdirectory
    74.   If Handler = -1 Then Exit Sub 'No subdirectories? Damn!!
    75.   RaiseEvent ChangeDir(Path)
    76.   DoEvents
    77.   Do
    78.     TmpFile = Left(FindInfo.cFileName, InStr(FindInfo.cFileName, vbNullChar) - 1)  'Truncate all the nulls chars at the end of the string
    79.     If TmpFile <> "." And TmpFile <> ".." Then If (GetFileAttributes(Path + TmpFile) And vbDirectory) = vbDirectory Then FindDirectories Path + TmpFile, Mask 'Let's make sure that it's really a directory. If so, we called again the FindDirectory sub
    80.     Result = FindNextFile(Handler, FindInfo) 'Find files in this subdirectory
    81.   Loop Until Result = 0 'Loop until no more subdirectories are found
    82.   FindClose Handler
    83. End Sub
    84.  
    85. Public Function Search(Path As String, Mask As String) As Variant
    86.   On Error Resume Next
    87.   Dim FindInfo As WIN32_FIND_DATA
    88.   Dim TmpFile As String
    89.   Dim Handler As Long, Result As Long
    90.  
    91.   ReDim Files(0) 'Allocate the files array
    92.   If Right(Path, 1) <> "\" Then Path = Path + "\"
    93.   FindFiles Path, Mask 'Find files in the main directory
    94.   Handler = FindFirstFile(Path + "*.*", FindInfo) 'Are there some other things in the directory?
    95.   If Handler <> -1 Then 'Yeah, It seems so
    96.     Do
    97.       TmpFile = Left(FindInfo.cFileName, InStr(FindInfo.cFileName, vbNullChar) - 1)
    98.       If TmpFile <> "." And TmpFile <> ".." Then If (GetAttr(Path + TmpFile) And vbDirectory) = vbDirectory Then FindDirectories Path + TmpFile, Mask 'If it's not a subdirectory, just ignore it
    99.       Result = FindNextFile(Handler, FindInfo) 'No explanation needed
    100.     Loop Until Result = 0 'Blah blah blah...
    101.   End If
    102.   FindClose Handler
    103.   Files(0) = UBound(Files) 'How many files we found??
    104.   Search = Files 'If we don't return the array, what do we call the function for?
    105.   Erase Files 'I don't know if the allocated space is deallocated automatically or not, but VB is tricky so we deallocate it manually...we just lose some milliseconds in the process
    106. End Function

  4. #4
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: little issue here...

    well the class is written in the way that don't alows you to search for more filetypes at once (if i've read it good, i'k sleepy ) so you have to search one type at time or you should rewrite the searching code...

  5. #5

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    Quote Originally Posted by krckoorascic
    well the class is written in the way that don't alows you to search for more filetypes at once (if i've read it good, i'k sleepy ) so you have to search one type at time or you should rewrite the searching code...
    yeah thats what i thought but i didn't write the class, a friend started on a program for me but then went missing in action, so im trying to do it myself . Have no idea how to rewrite this code. thanks for your reply

  6. #6

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    can someone help write this class for me to search for *.bmp;*.jpg; or point me to where i can download code bank

  7. #7

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    *bump*

  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: little issue here...

    sorry i cannot help with the code right now, but can give you an idea.

    in the SEARCH function, split the Mask parameter into a temp string array. example you have *.jpg;*.bmp then split with ; as delimiter.

    then loop that array with different string here (probably):
    VB Code:
    1. Handler = FindFirstFile(Path + "*.*", FindInfo)
    2. 'instead of "*.*", use the array's index which have *.jpg, *.bmp etc

    hope it helps you. i dont have PC with VB right now so i cannot try it, but this should probably work.
    Show Appreciation. Rate Posts.

  9. #9

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    im totally lost here buddie, maybe when you get back on a pc that has vb on it you can check the code out.

  10. #10

    Thread Starter
    Addicted Member thekurbster's Avatar
    Join Date
    Mar 2006
    Posts
    173

    Re: little issue here...

    well buddie i want to thank you cause i did fnd the solution by looking closely at what you wrote on your code, thanks a bunch!!!

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