Code: Select all
; Dynamic recursive file finder wih stored results
; KingLestat
; June/2007
; PB v4.02
EnableExplicit
Macro GlobalNewDynamicListPointer(Name, Type)
If 0
Global NewList Name.Type()
EndIf
EndMacro
Macro NewDynamicListPointer(Name, Type)
If 0
NewList Name.Type()
EndIf
EndMacro
Macro BindListTemplate(Type)
Procedure BindList#Type(List.Type(), ID.q)
!mov eax, [p.v_ID]
!mov edx, [p.v_ID+4]
!mov ecx, [p.v_ID-4]
!mov [ecx], eax
!add ecx, 4
!mov [ecx], edx
EndProcedure
EndMacro
Macro DynamicNewListTemplate(Type)
Procedure.q DynamicNewList#Type()
Protected NewList Local.Type()
!mov eax, [esp]
!mov edx, [esp+4]
!add esp, 8
!ret
EndProcedure
EndMacro
Macro FreeListTemplate(Type)
Procedure FreeList#Type(ID.q)
If 0
NewList Dummy.Type()
EndIf
BindList#Type(Dummy(), ID.q)
EndProcedure
EndMacro
Macro UseListType(Type)
BindListTemplate(Type)
DynamicNewListTemplate(Type)
FreeListTemplate(Type)
EndMacro
Structure stInfo
name.s
md5.s
size.l
EndStructure
Structure stName
name.s
EndStructure
Global Dim gListArray.q ( 4 )
UseListType ( stInfo )
UseListType ( stName )
GlobalNewDynamicListPointer ( ptrList1, stInfo )
GlobalNewDynamicListPointer ( ptrList2, stName )
Procedure InfoPath ( filename.s )
AddElement ( ptrList1() )
ptrList1()\name = filename
ptrList1()\md5 = MD5FileFingerprint ( Filename )
ptrList1()\size = FileSize ( filename )
EndProcedure
Procedure JustName ( filename.s )
AddElement ( ptrList2() )
ptrList2()\name = filename
EndProcedure
Procedure FindFileEx ( command.l, mask.l, root.s, func.l )
Protected temp.s
Static NewList llmask.s()
If command = 1
Protected i.l
Protected filemask.s
ClearList ( llmask() )
filemask = PeekS ( mask )
i & 0
i + 1
temp = StringField ( filemask, i, ";" )
Repeat
AddElement ( llmask() )
llmask() = temp
i + 1
temp = StringField ( filemask, i, ";" )
Until temp = ""
command + 1
EndIf
If command = 2
Protected df.l
Protected skip.l
ForEach llmask()
df = ExamineDirectory ( #PB_Any, root, llmask() )
If df > 0
While NextDirectoryEntry ( df )
If DirectoryEntryType ( df ) = #PB_DirectoryEntry_File
CallFunctionFast ( func, root + "\" + DirectoryEntryName ( df ) )
EndIf
Wend
EndIf
Next
df = ExamineDirectory ( #PB_Any, root, "" )
If df > 0
skip & 0
While NextDirectoryEntry ( df )
If DirectoryEntryType ( df ) = #PB_DirectoryEntry_Directory
skip + 1
If skip > 2
temp = DirectoryEntryName ( df )
FindFileEx ( 2, 0, root + "\" + temp, func )
EndIf
EndIf
Wend
EndIf
EndIf
EndProcedure
OpenConsole()
gListArray ( 0 ) = DynamicNewListstInfo ()
gListArray ( 1 ) = DynamicNewListstName ()
BindListstName ( ptrList2(), gListArray ( 1 ) )
FindFileEx ( 1, @"*.hlp;*.inf;*.ocx", "c:\windows", @JustName() )
ForEach ptrList2()
PrintN ( ptrList2()\name )
Next
BindListstInfo ( ptrList1(), gListArray ( 0 ) )
FindFileEx ( 1, @"b*.dll;*.ocx", "c:\windows", @InfoPath() )
ForEach ptrList1()
PrintN ( ptrList1()\name + " [" + ptrList1()\md5 + "] " + Str ( ptrList1()\size ) )
Next
End
command is always 1 (though I mean to add other params)
mask is address of files you want to look for wild cards included
root is the starting dir
func is function which takes string as parameter (which is full path of filename) and which you can do anything you like
If you have any ideas of how to optimize please let me know and I hope you find it usefull
cheers
KingLestat
[/code]