Page 1 of 1

Problem with OS X packages in recursive folder contents list

Posted: Sun Jul 20, 2014 8:09 am
by japino
Hi, I'm having a problem with recursively listing folder contents on a folder that contains packages in OS X. Keynote and Pages files in OS X are in fact folders that contain dozens of files. When I use the scripts found here:

http://lessons.runrev.com/m/4067/l/1708 ... ers-part-2

I get something like this as the result:

Code: Select all

testfile.png
FolderA/testfile1.png
FolderB/testfile2.png
FolderB/testfile3.png
FolderB/test.key/Index.zip
FolderB/test.key/preview-micro.jpg
FolderB/test.key/preview-web.jpg
FolderB/test.key/preview.jpg
FolderB/test.key/Data/big.jpg
...and 60 files more inside test.key
Obviously, I only want to get this:

Code: Select all

testfile.png
FolderA/testfile1.png
FolderB/testfile2.png
FolderB/testfile3.png
FolderB/test.key
I think I will be able to write some code in Livecode which checks for lines with ".key" for example and leaves just one and then for that 1 line remove the filename, leaving only ".key" at the end, but it seems to be a lot of trouble for something which seems to simple. I've also tried using shell scripts ("ls" or "find" for example) in Terminal, thinking that may be I could try a shell command, but they don't respect packages either. Any advice is very welcome!

Re: Problem with OS X packages in recursive folder contents

Posted: Sun Jul 20, 2014 10:11 pm
by jacque
Here is a function that uses AppleScript to find all the packages in a folder:

Code: Select all

function thePackages pFolder
    put revMacFromUnixPath(pFolder) into pFolder
    
    put "tell application" && quote & "Finder" & quote & cr & "packages of folder" \
    && quote & pFolder & quote & cr & "end tell" into tScr
    do tScr as applescript
    put the result into tList
    replace comma with cr in tList
     
    repeat for each line L in tList
        get wordoffset("file", L)
        put word it + 1 of L & cr after tPackages
    end repeat
    replace quote with empty in tPackages
    return char 1 to -2 of tPackages
end thePackages
You could run this for the folder, then compare its result to the list you get from "the files". If a so-called "file" is in the packages list, delete it from your final "files" list.

Re: Problem with OS X packages in recursive folder contents

Posted: Mon Jul 21, 2014 4:30 pm
by japino
Awesome, thank you Jacque!