Results 1 to 4 of 4

Thread: Indexing a NTFS volume on the network

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2001
    Location
    VA, USA
    Posts
    36

    Indexing a NTFS volume on the network

    I have a small problem, i finally got the search routine for a specific file worked out, but it is ooooooooooooooold dog slow. i was wondering if there is a way to index all files of a certain type prior to the main program running so that all file locations are known and can be gotten to through a binary search??? would i just load the directory locations of all files into a array, sort and then search?? if i can do this it would be much quicker than what i have currently, which works but will put you to sleep.

    o yea, running NT4.0 with NTFS on the volume in question.

    second place is just the first loser...

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    what was the method you used to search the for the files???

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2001
    Location
    VA, USA
    Posts
    36
    this

    Public Function GetList(ByVal DirPath As String, ByVal FileName As String) _
    As String
    Dim aa As Long
    Dim a As Long
    Dim Cp As Long

    ' Exit if you Forgot to pass a Start Directory.

    GetList = ""
    If Len(DirPath) = 0 Then Exit Function

    ' Keep Count of Total Calls of this
    ' Function so we can unload all the Flist and tempdir Later

    dcount = dcount + 1

    ' Current Index
    Cp = dcount

    'Load and Set the Path on the control

    Load frmBOMExtraction.Flist(Cp)
    frmBOMExtraction.Flist(Cp).path = DirPath
    DoEvents

    ' Search For the File

    For a = 0 To frmBOMExtraction.Flist(Cp).ListCount - 1
    If LCase(frmBOMExtraction.Flist(Cp).List(a)) = LCase(FileName) Then
    ' File Found Return Path

    GetList = DirPath & "\" & frmBOMExtraction.Flist(Cp).List(a)
    Exit Function
    End If
    DoEvents
    Next a

    ' File Not Found

    Load frmBOMExtraction.TempDir(Cp)

    ' If there are sub directories. Search them.

    frmBOMExtraction.TempDir(Cp).path = DirPath
    If frmBOMExtraction.TempDir(Cp).ListCount > 0 Then
    For aa = 0 To frmBOMExtraction.TempDir(Cp).ListCount - 1
    GetList = GetList(frmBOMExtraction.TempDir(Cp).List(aa), FileName)
    If Len(GetList) <> 0 Then Exit For
    Next aa
    DoEvents
    End If
    End Function
    second place is just the first loser...

  4. #4
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    how about using the findFirstFile and findNextFile API??

    its much faster

    heres an example of what i have done in the past

    VB Code:
    1. Option Explicit
    2. Dim FindData As WIN32_FIND_DATA
    3. Dim FindHandle As Long
    4. Dim FindNextHandle As Long
    5. Dim filestring As String
    6.  
    7. Sub findfilesapi(DirPath As String, FileSpec As String)
    8. Dim txtCheck2() As String
    9. Dim txtCheck1 As String
    10. Dim isSame As Boolean
    11. Dim isThere As Boolean
    12. Dim isAdded As Boolean
    13. Dim x As Integer
    14. Dim strProgram() As String
    15. Dim strExe As String
    16. Dim strPath As String
    17. Dim strName As String
    18.  
    19. DirPath = Trim$(DirPath)
    20.  
    21. If Right(DirPath, 1) <> "\" Then
    22.   DirPath = DirPath & "\"
    23. End If
    24.  
    25. ' Find the first file in the selected directory
    26.  
    27. FindHandle = FindFirstFile(DirPath & FileSpec, FindData)
    28. If FindHandle <> 0 Then
    29.   If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
    30.     ' It's a directory
    31.     If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
    32.       filestring = DirPath & Trim$(FindData.cFileName) & "\"
    33.       lstsearch.AddItem filestring, 1
    34.     End If
    35.   Else
    36.     filestring = DirPath & Trim$(FindData.cFileName)
    37.     txtCheck2 = Split(filestring, "\", , 0)
    38.     x = UBound(txtCheck2)
    39.     txtCheck1 = txtCheck2(x)
    40.     txtCheck1 = LTrim$(txtCheck1)
    41.     isSame = LCase(txtCheck1) Like "*.exe*"
    42.    
    43.     If isSame = True Then
    44.        
    45.         strProgram = Split(txtCheck1, ".", , 0)
    46.         strName = strProgram(0)
    47.         strPath = LTrim(filestring)
    48.         strExe = txtCheck1
    49.         isThere = objData.CheckProgram(strExe)
    50.        
    51.         If isThere = False Then
    52.             isAdded = objData.AddProgramItem(strName, strPath, strExe)
    53.         End If
    54.     End If
    55.  
    56.   End If
    57. End If
    58.  
    59. ' Now loop and find the rest of the files
    60. If FindHandle <> 0 Then
    61.   Do
    62.  
    63.     DoEvents
    64.    
    65.     FindNextHandle = FindNextFile(FindHandle, FindData)
    66.     If FindNextHandle <> 0 Then
    67.       If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
    68.         ' It's a directory
    69.         If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
    70.           filestring = DirPath & Trim$(FindData.cFileName) & "\"
    71.           lstsearch.AddItem filestring, 1
    72.         End If
    73.       Else
    74.         filestring = DirPath & Trim$(StripNulls(FindData.cFileName))
    75.         txtCheck2 = Split(filestring, "\", , 0)
    76.         x = UBound(txtCheck2)
    77.         txtCheck1 = txtCheck2(x)
    78.         txtCheck1 = LTrim$(txtCheck1)
    79.         isSame = LCase(txtCheck1) Like "*.exe*"
    80.    
    81.     If isSame = True Then
    82.        
    83.         strProgram = Split(txtCheck1, ".", , 0)
    84.         strName = strProgram(0)
    85.         strPath = LTrim(filestring)
    86.         strExe = txtCheck1
    87.         isThere = objData.CheckProgram(strExe)
    88.        
    89.         If isThere = False Then
    90.             isAdded = objData.AddProgramItem(strName, strPath, strExe)
    91.         End If
    92.        
    93.     End If
    94.      
    95.       End If
    96.     Else
    97.       Exit Do
    98.     End If
    99.   Loop
    100. End If
    101.  
    102. ' It is important that you close the handle for FindFirstFile
    103. Call FindClose(FindHandle)
    104. End Sub
    105.  
    106. Private Sub cmdDone_Click()
    107. Dim intCount As Integer
    108. Dim lngNum As Long
    109. Dim arrProgs() As String
    110.  
    111.  
    112. lngNum = objData.enumPrograms(arrProgs)
    113.  
    114. If lngNum > 0 Then
    115.     frmremovecom.List1.Clear
    116.     lngNum = lngNum - 1
    117.    
    118.     For intCount = 0 To lngNum
    119.         If arrProgs(intCount) > "" Then
    120.             frmremovecom.List1.AddItem (arrProgs(intCount))
    121.         End If
    122.     Next intCount
    123.  
    124. End If
    125.  
    126. Unload Me
    127. frmremovecom.SetFocus
    128. End Sub
    129.  
    130. Private Sub Form_Activate()
    131. Dim SearchPath As String, FindStr As String
    132. Dim intCount As Integer
    133.  
    134. Screen.MousePointer = vbHourglass
    135. SearchPath = "c:\Program Files\"
    136. FindStr = "*.*"
    137. lstsearch.List(0) = SearchPath
    138. ProgressBar1.Min = 0
    139. ProgressBar1.Max = 5000
    140. intCount = 1
    141.  
    142. Do
    143.   ProgressBar1.Value = intCount
    144.   findfilesapi lstsearch.List(0), FindStr
    145.   lstsearch.RemoveItem 0
    146.   intCount = intCount + 1
    147. Loop Until lstsearch.ListCount = 0
    148.  
    149. Screen.MousePointer = vbDefault
    150. Picture3.Visible = True
    151. cmdDone.Visible = True
    152. ProgressBar1.Value = 5000
    153.  
    154.  
    155. End Sub
    156.  
    157. Private Sub Form_Load()
    158. Picture3.Visible = False
    159. cmdDone.Visible = False
    160. ProgressBar1.Visible = True
    161. End Sub

    this was just a little autosearch form I used in one of my apps
    you can should be able to grab the code you need for the search from the function

    in a module

    VB Code:
    1. Option Explicit
    2.  
    3. Declare Function FindFirstFile Lib "kernel32" Alias _
    4. "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData _
    5. As WIN32_FIND_DATA) As Long
    6. Declare Function FindNextFile Lib "kernel32" Alias _
    7. "FindNextFileA" (ByVal hFindFile As Long, _
    8. lpFindFileData As WIN32_FIND_DATA) As Long
    9. Declare Function GetFileAttributes Lib "kernel32" Alias _
    10. "GetFileAttributesA" (ByVal lpFileName As String) As Long
    11. Declare Function FindClose Lib "kernel32" (ByVal hFindFile _
    12. As Long) As Long
    13. Public Const MAX_PATH = 260
    14. Public Const MAXDWORD = &HFFFF
    15. Public Const INVALID_HANDLE_VALUE = -1
    16. Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    17. Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    18. Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    19. Public Const FILE_ATTRIBUTE_NORMAL = &H80
    20. Public Const FILE_ATTRIBUTE_READONLY = &H1
    21. Public Const FILE_ATTRIBUTE_SYSTEM = &H4
    22. Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
    23. Public Type FILETIME
    24.     dwLowDateTime As Long
    25.     dwHighDateTime As Long
    26. End Type
    27. Public 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 * MAX_PATH
    37.     cAlternate As String * 14
    38. End Type
    39.  
    40. Public Function StripNulls(OriginalStr As String) As String
    41. If (InStr(OriginalStr, Chr(0)) > 0) Then
    42.     OriginalStr = Left(OriginalStr, _
    43.     InStr(OriginalStr, Chr(0)) - 1)
    44. End If
    45. StripNulls = OriginalStr
    46. End Function

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