File/Folder List - Speed Test

Category: Files/Folders

Date: 02-16-2022

Return to Index


 
'Compilable Example:  (Jose Includes)
#Compiler PBWin 9, PBWin 10  Put filenames in an array of type DirData
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword, Folders(), Files() As DirData
Global qFreq, qStart, qStop As Quad, FolderCount, FileCount As Long
 
%IDC_FoldersBeene    = 500
%IDC_FilesBeene      = 600
%IDC_FolderList      = 700
%IDC_FileList        = 800
%IDC_StartPath       = 900
 
Function PBMain() As Long
   Dialog New Pixels, 0, "Test Code",300,300,385,420, %WS_OverlappedWindow To hDlg
   Control Add Button, hDlg, %IDC_FoldersBeene,"Get Folders _ Beene", 10,10,150,20
   Control Add Button, hDlg, %IDC_FilesBeene,"Get Files _ Beene", 175,10,150,20
   Control Add TextBox, hDlg, %IDC_StartPath, "c:\data\apps\powerbasic\apps_gbapps\gbsearch",10,40,365,20
   Control Add ListBox, hDlg, %IDC_FolderList,,10,70,175,250
   Control Add ListBox, hDlg, %IDC_FileList,,200,70,175,250
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   Local i As Long, temp$
   Select Case Cb.Msg
      Case %WM_InitDialog
         QueryPerformanceFrequency qFreq
         ReDim Folders(50000), Files(250000)
      Case %WM_Command
         Select Case Cb.Ctl
            Case %IDC_FoldersBeene
               'folders
               Reset Folders(), Files()
               QueryPerformanceCounter qStart
               '--------------------------------------------
               FolderCount = 0 : Control Get Text hDlg, %IDC_StartPath To temp$
               '                  GetFolderList_Beene(temp$)
               GetFolderList
               '--------------------------------------------
               QueryPerformanceCounter qStop
               ? "Folders: found " + Str$(FolderCount) + " in " + Format$((qStop-qStart)/qFreq,"0.###") & " seconds" + $CrLf _
                  + $CrLf + Folders(0).FileName + $CrLf + Folders(1).FileName + $CrLf +  Folders(2).FileName + $CrLf +  Folders(3).FileName + $CrLf +  Folders(4).FileName + $CrLf +  Folders(5).FileName
            Case %IDC_FilesBeene
               'files
               FolderCount = 0
               QueryPerformanceCounter qStart
               '--------------------------------------------
               For i = 0 To UBound(Folders())
               Next i
               '--------------------------------------------
               QueryPerformanceCounter qStop
               ? "Files: found " + Str$(FileCount) + " in " + Format$((qStop-qStart)/qFreq,"0.###") & " seconds"
         End Select
   End Select
End Function
 
Sub GetFolderList_Beene (ParentFolder$)
   Local iPOS As Long, tempDIR As DirData, temp$
   Folders(FolderCount).FileName = ParentFolder$
   While Len(Folders(iPOS).FileName)
      temp$ = Dir$(Folders(iPOS).FileName + "\*.*", Only %SubDir To tempDir)  'subfolders only
      tempDir.FileName = ParentFolder$ + "\" + tempDir.FileName
      While Len(temp$)
         Incr FolderCount
         Folders(FolderCount) =  tempDir
         Folders(FolderCount).FileName = Folders(iPos).FileName + "\" + temp$
         temp$ =  Dir$ (NextTo tempDir)
         tempDir.FileName = ParentFolder$ + "\" + tempDir.FileName
      Wend
      Incr iPOS
   Wend
End Sub
 
Sub GetFolderList
   Local iPOS As Long, temp$
   ReDim xFolders(50000) As String
   xFolders(FolderCount) = "c:\data"
   While Len(xFolders(iPOS))
      temp$ = Dir$(Build$(xFolders(iPOS),"\*.*"), Only %SubDir)  'subfolders only
      While Len(temp$)
         Incr FolderCount
         xFolders(FolderCount) =  Build$(xFolders(iPos),"\",temp$)
         temp$ =  Dir$ (Next)
      Wend
      Incr iPOS
   Wend
End Sub
   '   Folders(FolderCount) = RTrim$(sFolder,"\")
   '       While Len(Folders(iPOS))
   '          temp$ = Dir$(Build$(Folders(iPOS),"\*.*"), Only %SubDir)  'subfolders only
   '          While Len(temp$)
   '             If Debug Then cPrint Build$(Folders(iPos),"\",temp$)
   '             Incr FolderCount
   '             Folders(FolderCount) =  Build$(Folders(iPos),"\",temp$)
   '             temp$ =  Dir$ (Next)
   '          Wend
   '          Incr iPOS
   '       Wend
 
'gbs_00844
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm