Date: 02-16-2022
Return to Index
created by gbSnippets
'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_FilesBeene = 600
%IDC_FolderList = 700
%IDC_FileList = 800
%IDC_StartPath = 900
%IDC_FileSpec = 901
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",100,300,830,320, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_FilesBeene,"Get Files _ Beene", 10,10,150,20
' Control Add TextBox, hDlg, %IDC_StartPath, "c:\data\apps\powerbasic\apps_gbapps\gbsearch",10,40,400,20
Control Add TextBox, hDlg, %IDC_StartPath, "c:\data\apps",10,40,400,20
Control Add TextBox, hDlg, %IDC_FileSpec, "*.bas",420,40,400,20
Control Add ListBox, hDlg, %IDC_FolderList,,10,70,400,250
Control Add ListBox, hDlg, %IDC_FileList,,420,70,400,250
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i As Long, ParentFolder$, FileSpec$
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
ReDim Folders(75000), Files(300000)
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_FilesBeene
'folders
Reset Folders(), Files()
ListBox Reset hDlg, %IDC_FolderList
ListBox Reset hDlg, %IDC_FileList
FolderCount = 0 : FileCount = 0
Control Get Text hDlg, %IDC_StartPath To ParentFolder$
Control Get Text hDlg, %IDC_FileSpec To FileSpec$
QueryPerformanceCounter qStart
'--------------------------------------------
GetFolderList_Beene ParentFolder$
GetFileList_Beene FileSpec$
'--------------------------------------------
QueryPerformanceCounter qStop
Dialog Set Text hDlg, "Folders:" + Str$(FolderCount) + " Files:" + Str$(FileCount) + " " + Format$((qStop-qStart)/qFreq," 0.###") + " seconds"
For i = 0 To FolderCount : ListBox Add hDlg, %IDC_FolderList, Folders(i).FileName : Next i
For i = 0 To FileCount : ListBox Add hDlg, %IDC_FileList, Files(i).FileName : Next i
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$ (Next, To tempDir)
tempDir.FileName = ParentFolder$ + "\" + tempDir.FileName
Wend
Incr iPOS
Wend
End Sub
Sub GetFileList_Beene (FileSpec$)
Local i As Long, tempDir As DirData, temp$
For i = 0 To FolderCount
temp$ = Dir$(Folders(i).FileName + "\" + FileSpec$, To tempDir)
While Len(temp$)
Incr FileCount
Files(FileCount) = tempDir
temp$ = Dir$(Next, To tempDir)
Wend
Next i
End Sub
'gbs_00843
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm