Problem with OS X packages in recursive folder contents list

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Problem with OS X packages in recursive folder contents list

Post by japino » Sun Jul 20, 2014 8:09 am

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!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Problem with OS X packages in recursive folder contents

Post by jacque » Sun Jul 20, 2014 10:11 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Problem with OS X packages in recursive folder contents

Post by japino » Mon Jul 21, 2014 4:30 pm

Awesome, thank you Jacque!

Post Reply