I have written the script posted here to try to group files and folder into their containing path. What I hope to get at the end is:
{{“volume:mainfolder:folder:subfolder”, “file.ext”, “file2.ext”, “file3.ext”}, {“volume:mainfolder:folder”, “subfolder”, “subfolder2”, “file4.ext”, “file5.ext”}}
but what I get is:
{{“volume:mainfolder:folder:subfolder”, “file.ext”, “file2.ext”, “file3.ext”}, {“volume:mainfolder:folder”, “subfolder”, “subfolder2”, “file4.ext”, “file5.ext”}, {“volume:mainfolder:folder”, “subfolder2”}, {“volume:mainfolder:folder”, “file4.ext”}, {“volume:mainfolder:folder”, “file5.ext”}}
Ultimately I will provide a full path with a list of files or folders under it like so:
afp://volume/mainfolder/folder/subfolder
file.ext
file2.ext
file3.ext
afp://volume/mainfolder/folder
subfolder
subfolder2
file4.ext
file5.ext
I can see my logic is faulty and I might be going about this in a very clumsy way. Any help appreciated.
set pathsAndNames to {¬
"volume:mainfolder:folder:subfolder:file.ext", ¬
"volume:mainfolder:folder:subfolder", ¬
"volume:mainfolder:folder:subfolder2", ¬
"volume:mainfolder:folder:subfolder:file2.ext", ¬
"volume:mainfolder:folder:subfolder:file3.ext", ¬
"volume:mainfolder:folder:file4.ext", ¬
"volume:mainfolder:folder:file5.ext"}
set orderedList to {}
repeat with i from 1 to count of pathsAndNames
set thisItem to item i of pathsAndNames
set AppleScript's text item delimiters to ":"
set thisItemContainer to (text items 1 through -2 of thisItem) as string
set thisItemName to (text items -1 through -1 of thisItem) as string
set AppleScript's text item delimiters to ""
log thisItemContainer
log thisItemName
-- this is the bit that is going wrong
if (count of orderedList) is not 0 then
repeat with x from 1 to count of orderedList
if thisItemContainer is in item x of orderedList then
set end of item x of orderedList to thisItemName
exit repeat
else
set end of orderedList to {thisItemContainer, thisItemName}
end if
end repeat
else
set end of orderedList to {thisItemContainer, thisItemName}
end if
end repeat
return orderedList
Model: MacBook Pro 2.7 GHz Core i7 16GB RAM
Browser: Safari 537.31
Operating System: Mac OS X (10.8)