Post by thelostworld on Jul 29, 2009 15:46:27 GMT -5
He's not been on/not answering my PMs, so I was wondering of anyone could help me dissect this searching program of his:
It looks promising and I was wondering if there was a way to get it to search an imputed variable instead of just listing every file. I think it could be useful because it also lists hidden files.
color (50, 50, 200)
ResizeText(50, 30)
Dim Texture : Texture = LoadTexture("Font\lucida_console.png")
texture = LoadTex("Font\lucida_console.png")
Font (texture)
Function &ReturnAllFileNamesInDir (__Path as string, __FileName as string) () as string
'Pointers
Dim &__File() as string
Dim &__Backup() as string
'Search string
Dim __Search as string
'For loop
Dim __i
__Search = FindFirstFile (__Path + __FileName)
Do Until __Search = ""
&__Backup = &__File
Alloc __File, (ArrayMax(__Backup) + 1)
For __i = 0 to ArrayMax(__Backup)
__File(__i) = __Backup(__i)
Next
__File(__i) = __Search
__Search = FindNextFile()
Loop
FindClose()
Return &__File
EndFunction
Function &ReturnAllFolderNamesInDir (__Path as string) () as string
'Pointers
Dim &__Folder() as string
Dim &__Backup() as string
'Search string
Dim __Search as string
'For loop
Dim __i
__Search = FindFirstFile (__Path + "*.")
Do Until __Search = ""
if __Search <> "." AND __Search <> ".." Then
&__Backup = &__Folder
Alloc __Folder, (ArrayMax (__Folder) + 1)
For __i = 0 to ArrayMax(__Backup)
__Folder(__i) = __Backup(__i)
Next
__Folder(__i) = __Search + "/"
Endif
__Search = FindNextFile()
Loop
FindClose()
Return &__Folder
EndFunction
Function &AddStringPointerToPointer (&P1() as string, P2() as string) () as string
Dim &B() as string = &P1
Dim __i
Alloc P1, (ArrayMax(P1) + ArrayMax(P2) + 1)
For __i = 0 to ArrayMax(B)
P1(__i) = B(__i)
Next
For __i = 0 to ArrayMax(P2)
P1(ArrayMax(B) + __i + 1) = P2(__i)
Next
Return &P1
EndFunction
Function &ReturnAllFileNames (__Path as string, __FileName as string) () as string
'Pointers
Dim &__Folders_1() as string
Dim &__Folders_2() as string = ReturnAllFolderNamesInDir (__Path) 'Get starting folders
Dim &allfiles() as string, &filesindir() as string
'Loop vars
Dim __j, __i
'Other vars
Dim Complete = FALSE
Dim FoldersFound1
Dim FoldersFound2
Dim LastCount
Dim Count = 0
if &__Folders_2 = NULL Then
Return NULL
Endif
'Find all folders
Do
LastCount = ArrayMax(__Folders_2)
&__Folders_1 = ReturnAllFolderNamesInDir (__Path + __Folders_2(Count))
if &__Folders_1 <> NULL Then
&__Folders_2 = AddStringPointerToPointer (__Folders_2, __Folders_1)
Endif
FoldersFound1 = ArrayMax(__Folders_1)
FoldersFound2 = ArrayMax(__Folders_2)
For __i = LastCount to (LastCount + FoldersFound1)
__Folders_2(__i + 1) = __Folders_2(Count) + __Folders_2(__i + 1)
Next
Count = Count + 1
if Count = FoldersFound2 Then
Complete = TRUE
Endif
Loop Until Complete
'Get files now!
For __i = 0 to ArrayMax(__Folders_2)
&filesindir = ReturnAllFileNamesInDir (__Path + __Folders_2(__i), __FileName)
if &filesindir <> NULL Then
&AllFiles = AddStringPointerToPointer (AllFiles, FilesinDir)
Endif
Next
Return &allfiles
EndFunction
Dim &f() as string = ReturnAllFileNames ("", "*.*")
Dim i
For i = 0 to ArrayMax(f)
Printr f(i)
Sleep(300)
Next
It looks promising and I was wondering if there was a way to get it to search an imputed variable instead of just listing every file. I think it could be useful because it also lists hidden files.