Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button = 500
IDC_TextBox
End Enum
Global hDlg,hIcon As Dword, ParentFolder$
Global Files(), Folders() As DirData
Global FileCount, FolderCount As Long
Function PBMain() As Long
Dialog Default Font "Tahoma", 12, 1
Dialog New Pixels, 0, "gbGetFilesAndFolders",300,300,400,100, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Create File List", 20,10,150,25
Control Add TextBox, hDlg, %IDC_TextBox,"c:\data", 10,50,380,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
hIcon = LoadIcon(ByVal %Null, ByVal %IDI_Information) 'use a system icon for the dialog
SendMessage hDlg, %WM_SetIcon, %ICON_BIG, hIcon 'use a system icon for the dialog
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
FileCount = 0 : FolderCount = 0
Control Get Text hDlg, %IDC_TextBox To ParentFolder$
If IsFolder(ParentFolder$) Then GetFilesAndFolders
? "FolderCount: " + Str$(FolderCount) + $CrLf + "File Count: " + Str$(FileCount)
End Select
End Select
End Function
Sub GetFilesAndFolders
Local iPos As Long, tempDIR As DirData, temp$
FolderCount = 0 : FileCount = 0
ReDim Folders(250000), Files(750000)
Folders(iPos).FileName = ParentFolder$ 'no ending \
Do While Len(Folders(iPos).FileName)
temp$ = Dir$(Folders(iPos).FileName + "\*.*", %Normal + %SubDir, To tempDir)
Do While Len(temp$)
tempDir.FileName = Folders(iPos).FileName + "\" + tempDir.FileName 'add full path to filename
If (tempDir.FileAttributes And %File_Attribute_Directory) = 0 Then 'files
Incr FileCount
Files(FileCount) = tempDir
Else 'folder
Incr FolderCount
Folders(FolderCount) = tempDir
End If
temp$ = Dir$(Next, To tempDir)
Loop
Incr iPos
Loop
ReDim Preserve Files(FileCount)
ReDim Preserve Folders(FolderCount)
End Sub
http://www.garybeene.com/sw/gbsnippets.htm