I'm trying to do a threaded function that needs to call itself for recursion...
This is what I have done so far:
Code: Select all
DeclareModule SimpleScanDir
Structure SSD_PARAMS
Map ItemInfos.i()
path.s
pattern.s
EndStructure
NewMap PathExclusions.s()
PathExclusions(".") = ""
PathExclusions("..") = ""
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
PathExclusions("$recycle.bin") = ""
PathExclusions("system volume information") = ""
CompilerEndIf
Declare.i ScanDir(*SSDThread.SSD_PARAMS)
EndDeclareModule
; *************************************************************************************************
; *************************************************************************************************
Module SimpleScanDir
EnableExplicit
Procedure.i ScanDir(*SSDThread.SSD_PARAMS)
Protected.i hDir
If *SSDThread\path = "" : ProcedureReturn 0 : EndIf
If Right(*SSDThread\path, 1) <> #PS$ : *SSDThread\path + #PS$ : EndIf
hDir = ExamineDirectory(#PB_Any, *SSDThread\path, *SSDThread\pattern)
If hDir
While NextDirectoryEntry(hDir)
Select DirectoryEntryType(hDir)
Case #PB_DirectoryEntry_Directory
; Skip on defined entries
If FindMapElement(SimpleScanDir::PathExclusions(), LCase(DirectoryEntryName(hDir)))
Continue
EndIf
; Recurse
*SSDThread\path = *SSDThread\path + DirectoryEntryName(hDir) + #PS$
ScanDir(*SSDThread.SSD_PARAMS)
Case #PB_DirectoryEntry_File
Debug "Date: " + Str(DirectoryEntryDate(hDir, #PB_Date_Created)) + " | File: " + *SSDThread\path + DirectoryEntryName(hDir)
*SSDThread\ItemInfos(*SSDThread\path + DirectoryEntryName(hDir)) = DirectoryEntryDate(hDir, #PB_Date_Created)
EndSelect
Wend
FinishDirectory(hDir)
EndIf
;ClearStructure(*SSDThread, SSD_PARAMS)
;FreeMemory(*SSDThread)
ProcedureReturn MapSize(*SSDThread\ItemInfos())
EndProcedure
EndModule
Code: Select all
*SSDThread.SimpleScanDir::SSD_PARAMS = AllocateMemory(SizeOf(SimpleScanDir::SSD_PARAMS))
NewMap *SSDThread\ItemInfos()
*SSDThread\path = "D:\Install"
*SSDThread\pattern = "*.*"
CreateThread(SimpleScanDir::@ScanDir(), *SSDThread)
Code: Select all
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\@Homepage [Download].url
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\Windows 7\v1.2.1.359 [Preferred]\@Supported controllers.txt
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\Windows 7\v1.2.1.359 [Preferred]\x64\amd_sata.cat
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\Windows 7\v1.2.1.359 [Preferred]\x64\amd_sata.inf
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\Windows 7\v1.2.1.359 [Preferred]\x64\amd_sata.sys
Date: 1567678890 | File: D:\Install\Drivers\AMD\AHCI\Windows 7\v1.2.1.359 [Preferred]\x64\amd_xata.sys
01. D:\Install contains about 2560 files, why does the debug output does only list the above?
02. How should I handle the ClearStructure and FreeMemory part? I can't use them directly because of the recursion. Make a new function out of it that is called when the thread has finished?