After a couple days trying to work this out, I was finally able to figure out all the nuances of the Folder commands.
I have not seen anything on the site except for MadLibs plugin, and I wasn't sure it could do what I wanted. Plus, I didn't want to take time to learn how to use plug-ins.
So far, this works for me. Not saying its bug-free.
This example does not pick up files directly in the media folder, only subfolders. And my example only picks up PNGs and JPGs. But, easily adjustable.
type Images
Dir as string
ImgId
memblockID
endtype
function GetAllImagesFromFolders(ImagesFromFoldersArray as Images[])
//AllImagesForAssetDisplay = CreateMemblock()
defaultfolder$ = "/media" // ***Note the forwardslash MUST be in first*** this takes us back to media
SetFolder(defaultfolder$)
CompletedFolderArray as string[] // Array to keep track of folders so we don't revisit
PreviousFolderArray as string[] //Array to point to point back to previous folders
PreviousFolderArray.insert( defaultfolder$)
workingFolder$ = GetFirstFolder()
MainFolderCount = GetFolderCount()
CurrentMainFolder = 0
for i = 0 to MainFolderCount
SetFolder(workingFolder$) // this should always set us in a folder in /media
repeat // start
repeat //looking for the deepest folder
CurrentFolder$ = GetFolder()
NextFolder$ = TestForFolderHistory(CompletedFolderArray)
if NextFolder$ <> "" // save pointer to get back
if CurrentFolder$ <> IsFolderInArray(CurrentFolder$,PreviousFolderArray)
PreviousFolderArray.insert( CurrentFolder$ )
endif
SetFolder(NextFolder$) //sets folder
workingFolder$ = NextFolder$
endif
until NextFolder$ = ""
workingFolder$ = "/"+PreviousFolderArray[PreviousFolderArray.length] // Note "/" needs to be before or you will jump to a nonexistent directory
PreviousFolderArray.remove(PreviousFolderArray.length) //remove a level
CurrentFolder$ = GetFolder()
ImagesFromFoldersArray = InsertFolderImagesIntoImageArray(ImagesFromFoldersArray) //save your images or files
CompletedFolderArray.Insert( CurrentFolder$ ) // mark directory as done
SetFolder(workingFolder$)
until PreviousFolderArray.length = -1 // this puts us back at /media
SetFolder(workingFolder$)
PreviousFolderArray.insert(GetFolder())
//get next folder
workingFolder$ = TestForFolderHistory(CompletedFolderArray)
next i
endfunction ImagesFromFoldersArray
function InsertFolderImagesIntoImageArray(imgArray as Images[])
Img as Images
CurrentFolder$ = GetFolder()
file$ = GetFirstFile()
filecount = GetFileCount()
for i = 0 to filecount
if right(file$, 3) = "png" or right(file$,3) = "jpg" // change to the files you want or get rid of if you want all files
Img.dir = CurrentFolder$+file$
imgArray.insert( Img )
endif
file$ = GetNextFile()
next i
endfunction imgArray
function TestForFolderHistory(CompletedFolderArray as string[])
CurrentFolder$ = GetFolder()
temp$ = GetFirstFolder()
NextFolder$ = CurrentFolder$+temp$
if mid(NextFolder$,len(NextFolder$),1) <> "/" then NextFolder$ = NextFolder$+"/"
if NextFolder$ = IsFolderInArray(NextFolder$,CompletedFolderArray)
repeat
temp$ = GetNextFolder()
NextFolder$ = CurrentFolder$+temp$
if mid(NextFolder$,len(NextFolder$),1) <> "/" then NextFolder$ = NextFolder$+"/"
until IsFolderInArray(NextFolder$,CompletedFolderArray) = ""
workingFolder$ = temp$
else
workingFolder$ = temp$
endif
endfunction workingFolder$
function IsFolderInArray(workingFolder$,FolderArray as string[])
folder$ = ""
t = FolderArray.length
for i = 0 to FolderArray.length
n$ = FolderArray[i]
if FolderArray[i] = workingFolder$ then exitfunction workingFolder$
next i
endfunction folder$