Hi, my background is knowledgeable about other programming languages, unitiated with AppleScript.
Anyway, my current task is to read a folder structure without knowing what folder will be in it, nor what folders will have inside of them. It seems that get the entire contents of a folder will return every folder or file nestled within the folder, but as a flat list. I would like a list of lists, each list representing a folder, and a reference to a file at the “end” of the branching in the “final” list(s).
It seems that recursive functions are the way to go.
My first question is “Is that correct?”
My second question, assuming that the answer to the first is “Yes,” is what is the proper way to do this? I seem to get 70% of the way there then something goes kaput. I’m sure this is just my lack of experience in the AppleScript language, but I’ve also have not had good luck finding answers on the Internets.
Here’s the basic idea of what I’ve got so far…
set thePath to "/Users/dru/Library/Preferences/Macromedia/Flash Player/#SharedObjects/5CARVELE/"
set theMacPath to POSIX file thePath
tell application "Finder"
set theFolders to my walkFolderStructure(folder theMacPath)
log theFolders
end tell
on walkFolderStructure(theFolder)
set theList to {}
repeat with f in every item in theFolder as list
set aFolder to walkFolderStructure(f)
copy aFolder to the end of theList
end repeat
return theList
end walkFolderStructure
I seem to get odd results, though. Empty values in a list, or just “item 1”, etc. I’m obviously missing a key element or three.
Incidentally, I’ll throw this out there in case it means something. I’m intending for this folder structure list to be brought into an AS Studio application. Basically I’m trying to build a file browser for a very specific folder (The location of the SharedObects for the Flash Player, in case you’re curious). Ultimately I’d like to browse the folders and files in an Outline View, and choose to view a file’s contents after browsing around selecting a file.
So basically I want to create a datasource out a folder structure. If I’m going about this completely the wrong way, please tell me now.