searching for latest created folder

Can you provide some example by which I can find the latest created folder in a parent folder .
I tried using
==================


put the folders of pathZipFile into testNames-- get all of the folders there
repeat with each item of testNames
put the folders of it into testRuns
answer latest
repeat with each item of testRuns
if it's creationdate is greater than latest then
put it's creationdate into latest
end if
end repeat
end repeat

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    Before I answer the question you asked, I'm going to guess that you are trying to get the logfile of the last run of a script. There's a pretty simple way of doing that:
    put file (the logFile of the last item of scriptResults("someScript"))
    
    The scriptResults function returns a list of property lists, one for each run of the specified script. They're returned in date order, so the last one in the list is the most recent run. One of the properties of the property list is the logfile, which is the full path to the logfile.txt.

    If you need to do this in some other directory, then this code should work for you:
    put the folders of "~/documents" into folderList
    sort folderList chronologically by the NSFileModificationDate of each
    put the last item of folderList
    
    The folders() function returns a list of file/folder objects, each of which has a number of properties, one of which is the modification date. If you just output one of the items in the list, it returns its description, which is just its name, but if you ask for something like "the keys of the last item of folderList" then you'll see all of the properties recorded for that folder.
Sign In or Register to comment.